---
# System prepended metadata

title: 1979. Find Greatest Common Divisor of Array
tags: [Leetcode, Easy]

---

# 1979. Find Greatest Common Divisor of Array
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/find-greatest-common-divisor-of-array/
## 思路 $O(max(N,m))$ $O(1)$ m是最小值
先找到最大最小值，然后用常规找GCD的方法求答案
## Code
```java=
class Solution {
    public int findGCD(int[] nums) {
        int min = 1001, max = 0;
        for(int i = 0;i < nums.length;i++){
            min = Math.min(min, nums[i]);
            max = Math.max(max, nums[i]);
        }
        int ans = 1;
        for(int i = 1;i <= min;i++){
            if(min%i==0 && max%i==0){
                ans = i;
            }
        }
        return ans;
    }
}
```