You are given an array of positive integers nums. Your task is to return the greatest common divisor (GCD) of all the elements in the array. The GCD is the largest positive integer that divides every element without leaving a remainder.
Input: nums = [12, 18, 24]
Output: 6
Explanation: The largest positive integer that divides 12, 18, and 24 exactly is 6.
Input: nums = [7, 13, 5]
Output: 1
Explanation: The numbers share no common factor greater than 1. Therefore, their GCD is 1.
Input: nums = [10]
Output: 10
Explanation: Since the array contains only one number, its GCD is the number itself: 10.
Sign in to write, run, and submit your solution against the full test suite.