GCD of Array
EasyMathArray
Description
Given a non-empty array of positive integers, return the greatest common divisor (GCD) of all elements.
Examples
Input:
nums = [12,18,24]Output:
6Explanation:
gcd(12,18)=6, gcd(6,24)=6.
Input:
nums = [7]Output:
7Explanation:
Single element returns itself.
Input:
nums = [5,11,13]Output:
1Explanation:
Coprime numbers yield 1.
Constraints
- •
1 ≤ nums.length ≤ 1000 - •
1 ≤ nums[i] ≤ 10⁹