五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 1250. Check If It Is a Good Array

2023-04-17 12:27 作者:您是打尖兒還是住店呢  | 我要投稿

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.

Return?True?if the array is?good?otherwise?return?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

?

Constraints:

  • 1 <= nums.length <= 10^5

  • 1 <= nums[i] <= 10^9

古代數(shù)學的剩余定理,如果2個數(shù)互質,a%b==1,那么就存在pa+qb=1,

所以只要數(shù)組中所有數(shù)字的最大公約數(shù)是1,那么他們就能組成1,否則不能;


Runtime:?3 ms, faster than?62.25%?of?Java?online submissions for?Check If It Is a Good Array.

Memory Usage:?52.6 MB, less than?29.80%?of?Java?online submissions for?Check If It Is a Good Array.


LeetCode 1250. Check If It Is a Good Array的評論 (共 條)

分享到微博請遵守國家法律
东宁县| 五指山市| 甘孜县| 海兴县| 长宁区| 阿鲁科尔沁旗| 垫江县| 桐柏县| 图们市| 乌拉特前旗| 长岭县| 尖扎县| 宁南县| 湘潭县| 喀喇沁旗| 柞水县| 安化县| 广灵县| 普格县| 永昌县| 和田市| 萝北县| 蒙城县| 宝清县| 普兰县| 渭南市| 迭部县| 垦利县| 涡阳县| 肇源县| 宾川县| 磴口县| 弋阳县| 定结县| 虹口区| 云霄县| 蒲江县| 盐池县| 容城县| 抚顺市| 睢宁县|