Give you an array of integers nums , Returns the maximum common divisor of the maximum number and the minimum number in an array .
The greatest common divisor of two numbers is the largest positive integer that can be divided by two numbers .
Input :nums = [2,5,6,9,10]
Output :2
explain :
nums The smallest number is 2
nums The biggest number is 10
2 and 10 The greatest common divisor of 2
Input :nums = [7,5,6,8,3]
Output :1
explain :
nums The smallest number is 3
nums The biggest number is 8
3 and 8 The greatest common divisor of 1
Input :nums = [3,3]
Output :3
explain :
nums The smallest number is 3
nums The biggest number is 3
3 and 3 The greatest common divisor of 3
2 <= nums.length <= 1000
1 <= nums[i] <= 1000
class Solution:
def findGCD(self, nums: List[int]) -> int:
min1 = min(nums)
max1 = max(nums)
ans = 0
for i in range(1, max1 + 1):
if min1 % i == 0 and max1 % i == 0:
ans = i
return ans