[
math
array
]
Leetcode 1250. Check If It Is a Good Array
Problem statement
https://leetcode.com/problems/check-if-it-is-a-good-array/
Solution
Actually what we need to check is that gcd of all numbers is equal to 1
.
Complexity
Time complexity is O(n)
if we assume that gcd is evaluated in O(1)
, space is O(1)
.
Code
class Solution:
def isGoodArray(self, nums):
return reduce(gcd, nums) == 1