File tree 5 files changed +87
-0
lines changed
Problemset/1250-Check If It Is a Good Array 5 files changed +87
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 1250. Check If It Is a Good Array
2
+ 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.
3
+
4
+ Return ` True ` if the array is ** good** otherwise return ` False ` .
5
+
6
+ #### Example 1:
7
+ <pre >
8
+ <strong >Input:</strong > nums = [12,5,7,23]
9
+ <strong >Output:</strong > true
10
+ <strong >Explanation:</strong > Pick numbers 5 and 7.
11
+ 5*3 + 7*(-2) = 1
12
+ </pre >
13
+
14
+ #### Example 2:
15
+ <pre >
16
+ <strong >Input:</strong > nums = [29,6,10]
17
+ <strong >Output:</strong > true
18
+ <strong >Explanation:</strong > Pick numbers 29, 6 and 10.
19
+ 29*1 + 6*(-3) + 10*(-1) = 1
20
+ </pre >
21
+
22
+ #### Example 3:
23
+ <pre >
24
+ <strong >Input:</strong > nums = [3,6]
25
+ <strong >Output:</strong > false
26
+ </pre >
27
+
28
+ #### Constraints:
29
+ * ` 1 <= nums.length <= 10^5 `
30
+ * ` 1 <= nums[i] <= 10^9 `
31
+
32
+ ## Solutions (Python)
33
+
34
+ ### 1. Solution
35
+ ``` Python
36
+ class Solution :
37
+ def isGoodArray (self , nums : List[int ]) -> bool :
38
+ return math.gcd(* nums) == 1
39
+ ```
Original file line number Diff line number Diff line change
1
+ # 1250. 检查「好数组」
2
+ 给你一个正整数数组 ` nums ` ,你需要从中任选一些子集,然后将子集中每一个数乘以一个 ** 任意整数** ,并求出他们的和。
3
+
4
+ 假如该和结果为 ` 1 ` ,那么原数组就是一个「** 好数组** 」,则返回 ` True ` ;否则请返回 ` False ` 。
5
+
6
+ #### 示例 1:
7
+ <pre >
8
+ <strong >输入:</strong > nums = [12,5,7,23]
9
+ <strong >输出:</strong > true
10
+ <strong >解释:</strong > 挑选数字 5 和 7。
11
+ 5*3 + 7*(-2) = 1
12
+ </pre >
13
+
14
+ #### 示例 2:
15
+ <pre >
16
+ <strong >输入:</strong > nums = [29,6,10]
17
+ <strong >输出:</strong > true
18
+ <strong >解释:</strong > 挑选数字 29, 6 和 10。
19
+ 29*1 + 6*(-3) + 10*(-1) = 1
20
+ </pre >
21
+
22
+ #### 示例 3:
23
+ <pre >
24
+ <strong >输入:</strong > nums = [3,6]
25
+ <strong >输出:</strong > false
26
+ </pre >
27
+
28
+ #### 提示:
29
+ * ` 1 <= nums.length <= 10^5 `
30
+ * ` 1 <= nums[i] <= 10^9 `
31
+
32
+ ## 题解 (Python)
33
+
34
+ ### 1. 题解
35
+ ``` Python
36
+ class Solution :
37
+ def isGoodArray (self , nums : List[int ]) -> bool :
38
+ return math.gcd(* nums) == 1
39
+ ```
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def isGoodArray (self , nums : List [int ]) -> bool :
3
+ return math .gcd (* nums ) == 1
Original file line number Diff line number Diff line change 679
679
[ 1247] [ 1247l ] |[ Minimum Swaps to Make Strings Equal] [ 1247 ] |![ py]
680
680
[ 1248] [ 1248l ] |[ Count Number of Nice Subarrays] [ 1248 ] |![ rb]   ;  ; ![ rs]
681
681
[ 1249] [ 1249l ] |[ Minimum Remove to Make Valid Parentheses] [ 1249 ] |![ rs]
682
+ [ 1250] [ 1250l ] |[ Check If It Is a Good Array] [ 1250 ] |![ py]
682
683
[ 1252] [ 1252l ] |[ Cells with Odd Values in a Matrix] [ 1252 ] |![ rs]
683
684
[ 1253] [ 1253l ] |[ Reconstruct a 2-Row Binary Matrix] [ 1253 ] |![ rb]   ;  ; ![ rs]
684
685
[ 1255] [ 1255l ] |[ Maximum Score Words Formed by Letters] [ 1255 ] |![ rs]
1996
1997
[ 1247 ] :Problemset/1247-Minimum%20Swaps%20to%20Make%20Strings%20Equal/README.md#1247-minimum-swaps-to-make-strings-equal
1997
1998
[ 1248 ] :Problemset/1248-Count%20Number%20of%20Nice%20Subarrays/README.md#1248-count-number-of-nice-subarrays
1998
1999
[ 1249 ] :Problemset/1249-Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README.md#1249-minimum-remove-to-make-valid-parentheses
2000
+ [ 1250 ] :Problemset/1250-Check%20If%20It%20Is%20a%20Good%20Array/README.md#1250-check-if-it-is-a-good-array
1999
2001
[ 1252 ] :Problemset/1252-Cells%20with%20Odd%20Values%20in%20a%20Matrix/README.md#1252-cells-with-odd-values-in-a-matrix
2000
2002
[ 1253 ] :Problemset/1253-Reconstruct%20a%202-Row%20Binary%20Matrix/README.md#1253-reconstruct-a-2-row-binary-matrix
2001
2003
[ 1255 ] :Problemset/1255-Maximum%20Score%20Words%20Formed%20by%20Letters/README.md#1255-maximum-score-words-formed-by-letters
3316
3318
[ 1247l ] :https://leetcode.com/problems/minimum-swaps-to-make-strings-equal/
3317
3319
[ 1248l ] :https://leetcode.com/problems/count-number-of-nice-subarrays/
3318
3320
[ 1249l ] :https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/
3321
+ [ 1250l ] :https://leetcode.com/problems/check-if-it-is-a-good-array/
3319
3322
[ 1252l ] :https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/
3320
3323
[ 1253l ] :https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix/
3321
3324
[ 1255l ] :https://leetcode.com/problems/maximum-score-words-formed-by-letters/
Original file line number Diff line number Diff line change 679
679
[ 1247] [ 1247l ] |[ 交换字符使得字符串相同] [ 1247 ] |![ py]
680
680
[ 1248] [ 1248l ] |[ 统计「优美子数组」] [ 1248 ] |![ rb]   ;  ; ![ rs]
681
681
[ 1249] [ 1249l ] |[ 移除无效的括号] [ 1249 ] |![ rs]
682
+ [ 1250] [ 1250l ] |[ 检查「好数组」] [ 1250 ] |![ py]
682
683
[ 1252] [ 1252l ] |[ 奇数值单元格的数目] [ 1252 ] |![ rs]
683
684
[ 1253] [ 1253l ] |[ 重构 2 行二进制矩阵] [ 1253 ] |![ rb]   ;  ; ![ rs]
684
685
[ 1255] [ 1255l ] |[ 得分最高的单词集合] [ 1255 ] |![ rs]
1996
1997
[ 1247 ] :Problemset/1247-Minimum%20Swaps%20to%20Make%20Strings%20Equal/README_CN.md#1247-交换字符使得字符串相同
1997
1998
[ 1248 ] :Problemset/1248-Count%20Number%20of%20Nice%20Subarrays/README_CN.md#1248-统计优美子数组
1998
1999
[ 1249 ] :Problemset/1249-Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README_CN.md#1249-移除无效的括号
2000
+ [ 1250 ] :Problemset/1250-Check%20If%20It%20Is%20a%20Good%20Array/README_CN.md#1250-检查「好数组」
1999
2001
[ 1252 ] :Problemset/1252-Cells%20with%20Odd%20Values%20in%20a%20Matrix/README_CN.md#1252-奇数值单元格的数目
2000
2002
[ 1253 ] :Problemset/1253-Reconstruct%20a%202-Row%20Binary%20Matrix/README_CN.md#1253-重构-2-行二进制矩阵
2001
2003
[ 1255 ] :Problemset/1255-Maximum%20Score%20Words%20Formed%20by%20Letters/README_CN.md#1255-得分最高的单词集合
3316
3318
[ 1247l ] :https://leetcode.cn/problems/minimum-swaps-to-make-strings-equal/
3317
3319
[ 1248l ] :https://leetcode.cn/problems/count-number-of-nice-subarrays/
3318
3320
[ 1249l ] :https://leetcode.cn/problems/minimum-remove-to-make-valid-parentheses/
3321
+ [ 1250l ] :https://leetcode.cn/problems/check-if-it-is-a-good-array/
3319
3322
[ 1252l ] :https://leetcode.cn/problems/cells-with-odd-values-in-a-matrix/
3320
3323
[ 1253l ] :https://leetcode.cn/problems/reconstruct-a-2-row-binary-matrix/
3321
3324
[ 1255l ] :https://leetcode.cn/problems/maximum-score-words-formed-by-letters/
You can’t perform that action at this time.
0 commit comments