We’re preparing your current view and syncing the latest data.
Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.
An array of integers, nums.
An integer representing the greatest common divisor of the smallest and largest number in the array.
2 <= nums.length <= 1000, 1 <= nums[i] <= 1000
Example 1
Input
[2, 5, 6, 9, 10]
Output
2
Explanation
The smallest number is 2 and the largest is 10. The GCD of 2 and 10 is 2.
Example 2
Input
[7, 5, 6, 8, 3]
Output
1
Explanation
The smallest number is 3 and the largest is 8. The GCD of 3 and 8 is 1.