diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /check_good_array.py | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'check_good_array.py')
-rw-r--r-- | check_good_array.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/check_good_array.py b/check_good_array.py new file mode 100644 index 0000000..b223b12 --- /dev/null +++ b/check_good_array.py @@ -0,0 +1,25 @@ +# 1250. Check If It Is a Good Array + +""" +given an array 'nums' of positive integers. your task is to select some +subset of 'nums', multiply each element by an integer and add all these +numbers. the array is said to be good if you can obtain a sum of 1 from the +array by any possible subset and multiplicand. return 'true' if the array is +good, otherwise return 'false' +""" + + +class Solution(object): + def isGoodArray(self, nums): + gcd = nums[0] + for i in nums: + while i: + gcd, i = i, gcd % i + return gcd == 1 + + +if __name__ == "__main__": + obj = Solution() + print(obj.isGoodArray([12, 5, 7, 23])) # expect: True + print(obj.isGoodArray([29, 6, 10])) # expect: True + print(obj.isGoodArray([3, 6])) # expect: False |