File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,196 LeetCode solutions in JavaScript
1
+ # 1,197 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
953
953
1247|[ Minimum Swaps to Make Strings Equal] ( ./solutions/1247-minimum-swaps-to-make-strings-equal.js ) |Medium|
954
954
1248|[ Count Number of Nice Subarrays] ( ./solutions/1248-count-number-of-nice-subarrays.js ) |Medium|
955
955
1249|[ Minimum Remove to Make Valid Parentheses] ( ./solutions/1249-minimum-remove-to-make-valid-parentheses.js ) |Medium|
956
+ 1250|[ Check If It Is a Good Array] ( ./solutions/1250-check-if-it-is-a-good-array.js ) |Hard|
956
957
1252|[ Cells with Odd Values in a Matrix] ( ./solutions/1252-cells-with-odd-values-in-a-matrix.js ) |Easy|
957
958
1261|[ Find Elements in a Contaminated Binary Tree] ( ./solutions/1261-find-elements-in-a-contaminated-binary-tree.js ) |Medium|
958
959
1267|[ Count Servers that Communicate] ( ./solutions/1267-count-servers-that-communicate.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1250. Check If It Is a Good Array
3
+ * https://leetcode.com/problems/check-if-it-is-a-good-array/
4
+ * Difficulty: Hard
5
+ *
6
+ * Given an array nums of positive integers. Your task is to select some subset of nums, multiply
7
+ * each element by an integer and add all these numbers. The array is said to be good if you can
8
+ * obtain a sum of 1 from the array by any possible subset and multiplicand.
9
+ *
10
+ * Return True if the array is good otherwise return False.
11
+ */
12
+
13
+ /**
14
+ * @param {number[] } nums
15
+ * @return {boolean }
16
+ */
17
+ var isGoodArray = function ( nums ) {
18
+ let gcd = nums [ 0 ] ;
19
+
20
+ for ( let num of nums ) {
21
+ while ( num !== 0 ) {
22
+ const temp = gcd % num ;
23
+ gcd = num ;
24
+ num = temp ;
25
+ }
26
+ if ( gcd === 1 ) return true ;
27
+ }
28
+
29
+ return gcd === 1 ;
30
+ } ;
You can’t perform that action at this time.
0 commit comments