package leetcode;

/**
 * https://leetcode.com/problems/find-greatest-common-divisor-of-array/
 */
public class Problem1979 {
    public int findGCD(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1979 prob = new Problem1979();
        System.out.println(prob.findGCD(new int[]{2,5,6,9,10})); // 2
        System.out.println(prob.findGCD(new int[]{7,5,6,8,3})); // 1
        System.out.println(prob.findGCD(new int[]{3,3})); // 3
    }
}

@@ -168,333 +168,354 @@
     
-// TODO%0A        return 0
+int max = Integer.MIN_VALUE;%0A        int min = Integer.MAX_VALUE
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1979 prob = new Problem1979();%0A        System.out.println(prob.findGCD(new int%5B%5D%7B2,5,6,9,10%7D)); // 2%0A        System.out.println(prob.findGCD(new int%5B%5D%7B7,5,6,8,3%7D)); // 1%0A        System.out.println(prob.findGCD(new int%5B%5D%7B3,3%7D)); // 3
+for (int num : nums) %7B%0A            max = Math.max(max, num);%0A            min = Math.min(min, num);%0A        %7D%0A        return gcd(min, max);%0A    %7D%0A%0A    private static int gcd(int a, int b) %7B%0A        if (b == 0) %7B%0A            return a;%0A        %7D%0A        return gcd(b, a %25 b);
 %0A   

Solve problem 1979