/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 求出a、b的最大公约数。
* @param a int
* @param b int
* @return int
*/
function gcd(a, b) {
// write code here
let temp = null;
while (a !== 0) {
//思路就是一直用b%a,然后将a赋值给b,将余数赋值给a,直到a == 0,然后将保存了取余运算的a的值的b返回
temp = b % a;
b = a;
a = temp;
}
return b
}
module.exports = {
gcd : gcd
}; 


京公网安备 11010502036488号