Find Greatest Common Divisor of Array
给一个数组, 求里面最大值和最小值的gcd.
class Solution {
public int findGCD(int[] nums) {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for(int n : nums){
max = Math.max(max, n);
min = Math.min(min, n);
}
return gcd(min, max);
}
public int gcd(int a, int b){
if(a == 0)
return b;
return gcd(b % a, a);
}
}