1979. Find Greatest Common Divisor of Array Easy
1/**
2 * [1979] Find Greatest Common Divisor of Array
3 *
4 * Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.
5 * The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
6 *
7 * Example 1:
8 *
9 * Input: nums = [2,5,6,9,10]
10 * Output: 2
11 * Explanation:
12 * The smallest number in nums is 2.
13 * The largest number in nums is 10.
14 * The greatest common divisor of 2 and 10 is 2.
15 *
16 * Example 2:
17 *
18 * Input: nums = [7,5,6,8,3]
19 * Output: 1
20 * Explanation:
21 * The smallest number in nums is 3.
22 * The largest number in nums is 8.
23 * The greatest common divisor of 3 and 8 is 1.
24 *
25 * Example 3:
26 *
27 * Input: nums = [3,3]
28 * Output: 3
29 * Explanation:
30 * The smallest number in nums is 3.
31 * The largest number in nums is 3.
32 * The greatest common divisor of 3 and 3 is 3.
33 *
34 *
35 * Constraints:
36 *
37 * 2 <= nums.length <= 1000
38 * 1 <= nums[i] <= 1000
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/find-greatest-common-divisor-of-array/
44// discuss: https://leetcode.com/problems/find-greatest-common-divisor-of-array/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn find_gcd(nums: Vec<i32>) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_1979() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.