Find Greatest Common Divisor of Array

Given an integer array nums, return gcd(min(nums), max(nums)). This is the standard array gcd problem that depends on the extreme values of the array.

Input Format

nums = array of positive integers

Output Format

gcd of the minimum and maximum elements in nums

Constraints

  • 1 <= nums.length <= 1000; 1 <= nums[i] <= 1000

Examples

Example 1:

Input:

nums = [2,5,6,9,10]

Output:

2

Explanation:

gcd(min=2, max=10) = 2.

Example 2:

Input:

nums = [7,5,6,8,3]

Output:

1

Explanation:

gcd(min=3, max=8) = 1.

Loading...
Find Greatest Common Divisor of Array - Math