Leetcode 2106 Solution

This article provides solution to leetcode question 2106 (find-greatest-common-divisor-of-array)

https://leetcode.com/problems/find-greatest-common-divisor-of-array

Solution

class Solution:
    def findGCD(self, nums: List[int]) -> int:
        small = sys.maxsize
        large = -sys.maxsize

        for num in nums:
            small = min(num, small)
            large = max(num, large)

        return self.findGCDForTwoNumbers(small, large)


    def findGCDForTwoNumbers(self, num1, num2):
        if num1 < num2:
            return self.findGCDForTwoNumbers(num2, num1)

        if num2 == 0:
            return num1

        return self.findGCDForTwoNumbers(num2, num1 % num2)