Date: 2026-06-06
Time: 16:37
This file solves LeetCode #1979 — Find Greatest Common Divisor of Array. Its sole responsibility is providing a Solution class with a findGCD method that computes the GCD of the minimum and maximum elements in an integer array. This follows the repo's convention of one problem per directory, each with a solution.py conforming to LeetCode's class-based submission format.
Solution.findGCD(nums: List[int]) -> int — The only method. Takes a list of positive integers (guaranteed length >= 2 by the problem constraints) and returns the GCD of min(nums) and max(nums). The implementation is a single expression — no intermediate state, no iteration beyond what min/max do internally.
math.gcd, which is a C-accelerated builtin. This is the idiomatic Python approach for GCD problems.gcd(min(nums), max(nums)) chains three pure functions with no mutation — a common pattern across this repo's simpler solutions.Solution wrapper class with a camelCase method name matches LeetCode's expected submission interface.Imports:
math.gcd — the actual GCD computationtyping.List — type annotation (required for LeetCode's Python 3 environment, though modern Python accepts list[int])Imported by: The test_solution.py in the same directory. The massive "Imported By" list in the prompt is a red herring — those are test files across the entire repo that each import their *own* directory's solution.py, not this one.
1. min(nums) — O(n) scan to find the smallest element
2. max(nums) — O(n) scan to find the largest element
3. gcd(smallest, largest) — Euclid's algorithm, O(log(min(a,b))) where a,b are the two values
4. Return the integer result
Total: O(n) time, O(1) space.
nums has at least 2 elements and all are positive integers (enforced by the problem, not by the code).min(nums) and max(nums), and no larger integer does.gcd(x, x) == x, which is correct — the GCD of a number with itself is that number.None. The code trusts LeetCode's constraints. Passing an empty list would raise ValueError from min()/max(). Passing non-integers would propagate whatever math.gcd raises. This is appropriate for a contest submission.
find-greatest-common-divisor-of-array/test_solution.py — See what edge cases are tested (single-pair, coprime inputs, identical elements)greatest-common-divisor-of-strings/solution.py — A harder GCD-based problem that applies the concept to strings rather than integersx-of-a-kind-in-a-deck-of-cards/solution.py — Another problem that likely uses math.gcd in a reduce/fold pattern over multiple valuesmath-gcd-cpython-impl — CPython's math.gcd uses the binary GCD algorithm in C; understanding it explains why delegating beats a pure-Python Euclid'sgcd-of-extremes — findGCD computes gcd(min(nums), max(nums)), not a pairwise GCD across all elementsstdlib-gcd-delegation — The solution delegates GCD computation entirely to math.gcd with no custom algorithmlinear-time-complexity — The dominant cost is the two O(n) scans for min and max; the GCD step is O(log(min_val))no-input-validation — The method performs no validation on nums — empty lists, negative values, or non-integers would propagate exceptions from stdlib calls