# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up