Skip to content

Commit 88f03e8

Browse files
authored
Create check-if-it-is-a-good-array.py
1 parent 35418c7 commit 88f03e8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Python/check-if-it-is-a-good-array.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def isGoodArray(self, nums):
6+
"""
7+
:type nums: List[int]
8+
:rtype: bool
9+
"""
10+
def gcd(a, b):
11+
while b:
12+
a, b = b, a%b
13+
return a
14+
15+
# Bézout's identity
16+
result = nums[0]
17+
for num in nums:
18+
result = gcd(result, num)
19+
if result == 1:
20+
break
21+
return result == 1

0 commit comments

Comments
 (0)