1250. Check If It Is a Good Array
Read the full problem statement on LeetCode.
Difficulty: hard Acceptance: 61% Topics: Array, Math, Number Theory
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def isGoodArray(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
def gcd(a, b):
while b:
a, b = b, a%b
return a
# Bézout's identity
result = nums[0]
for num in nums:
result = gcd(result, num)
if result == 1:
break
return result == 1
Solution from kamyu104/LeetCode-Solutions · MIT