Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bd4a1db

Browse files
committedApr 7, 2025
Add solution #1250
1 parent 420f463 commit bd4a1db

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,196 LeetCode solutions in JavaScript
1+
# 1,197 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -953,6 +953,7 @@
953953
1247|[Minimum Swaps to Make Strings Equal](./solutions/1247-minimum-swaps-to-make-strings-equal.js)|Medium|
954954
1248|[Count Number of Nice Subarrays](./solutions/1248-count-number-of-nice-subarrays.js)|Medium|
955955
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|
956957
1252|[Cells with Odd Values in a Matrix](./solutions/1252-cells-with-odd-values-in-a-matrix.js)|Easy|
957958
1261|[Find Elements in a Contaminated Binary Tree](./solutions/1261-find-elements-in-a-contaminated-binary-tree.js)|Medium|
958959
1267|[Count Servers that Communicate](./solutions/1267-count-servers-that-communicate.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
};

0 commit comments

Comments
 (0)
Please sign in to comment.