-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathcheck-if-it-is-a-good-array.md
37 lines (28 loc) · 1.16 KB
/
check-if-it-is-a-good-array.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<p>Given an array <code>nums</code> of positive integers. Your task is to select some subset of <code>nums</code>, multiply each element by an integer and add all these numbers. The array is said to be <strong>good </strong>if you can obtain a sum of <code>1</code> from the array by any possible subset and multiplicand.</p>
<p>Return <code>True</code> if the array is <strong>good </strong>otherwise return <code>False</code>.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [12,5,7,23]
<strong>Output:</strong> true
<strong>Explanation:</strong> Pick numbers 5 and 7.
5*3 + 7*(-2) = 1
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [29,6,10]
<strong>Output:</strong> true
<strong>Explanation:</strong> Pick numbers 29, 6 and 10.
29*1 + 6*(-3) + 10*(-1) = 1
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,6]
<strong>Output:</strong> false
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10^5</code></li>
<li><code>1 <= nums[i] <= 10^9</code></li>
</ul>