Learner Level
Implement the method gcd that returns the greatest common divisor of two integers.
Return the greatest common divisor of two non-negative integers. The result is the largest integer that divides both values without a remainder.
The task is designed to test careful handling of edge cases, not only the most common input.
- If one value is zero, return the other value.
- If both values are zero, return
0. - Use repeated remainder reduction for an efficient solution.
Apply the Euclidean algorithm by repeatedly replacing gcd(a, b) with gcd(b, a % b) until the second value becomes zero.