#1250
Check If It Is a Good Array
expert · 1165 · lc hard +32 · verified · 63.4% accepted · 569 likes · top 66%
Description
You are given an array nums of positive integers. An array is "good" if you can select some subset of elements, multiply each chosen element by some integer (positive, negative, or zero), and have the results sum to exactly 1.
Return True if the array is good, otherwise False.
Example 1:
Input: nums = [12,5,7,23]
Output: true
Explanation: Pick numbers 5 and 7.
5*3 + 7*(-2) = 1
Example 2:
Input: nums = [29,6,10]
Output: true
Explanation: Pick numbers 29, 6 and 10.
29*1 + 6*(-3) + 10*(-1) = 1
Example 3:
Input: nums = [3,6]
Output: false
Code
1
2
3