Class Solution
java.lang.Object
g1901_2000.s1979_find_greatest_common_divisor_of_array.Solution
1979 - Find Greatest Common Divisor of Array.<p>Easy</p>
<p>Given an integer array <code>nums</code>, return <em>the <strong>greatest common divisor</strong> of the smallest number and largest number in</em> <code>nums</code>.</p>
<p>The <strong>greatest common divisor</strong> of two numbers is the largest positive integer that evenly divides both numbers.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,5,6,9,10]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>The smallest number in nums is 2.</p>
<p>The largest number in nums is 10.</p>
<p>The greatest common divisor of 2 and 10 is 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [7,5,6,8,3]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>The smallest number in nums is 3.</p>
<p>The largest number in nums is 8.</p>
<p>The greatest common divisor of 3 and 8 is 1.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [3,3]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>The smallest number in nums is 3.</p>
<p>The largest number in nums is 3.</p>
<p>The greatest common divisor of 3 and 3 is 3.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= nums.length <= 1000</code></li>
<li><code>1 <= nums[i] <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findGCD
public int findGCD(int[] nums)
-