最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

LeetCode 2601. Prime Subtraction Operation

2023-03-26 14:31 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?integer array?nums?of length?n.

You can perform the following operation as many times as you want:

  • Pick an index?i?that you haven’t picked before, and pick a prime?p?strictly less than?nums[i], then subtract?p?from?nums[i].

Return?true if you can make?nums?a strictly increasing array using the above operation and false otherwise.

A?strictly increasing array?is an array whose each element is strictly greater than its preceding element.

?

Example 1:

Input: nums = [4,9,6,10]

Output: true

Explanation:?

In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0],?

so that nums becomes [1,9,6,10].?

In the second operation: i = 1, p = 7, subtract 7 from nums[1],?

so nums becomes equal to [1,2,6,10].?

After the second operation, nums is sorted in strictly increasing order, so the answer is true.

Example 2:

Input: nums = [6,8,11,12]

Output: true

Explanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.

Example 3:

Input: nums = [5,8,3]

Output: false

Explanation: It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false.

?

Constraints:

  • 1 <= nums.length <= 1000

  • 1 <= nums[i] <= 1000

  • nums.length == n

好尷尬啊,基本上每個(gè)函數(shù)都寫錯(cuò)過,isprime函數(shù)漏寫了1的情況,1不是質(zhì)數(shù),不是質(zhì)數(shù),不是質(zhì)數(shù)。。。。

first_numSubtract()這個(gè)函數(shù)是將第一個(gè)元素先降低到最小值,

然后剩下的元素去每次判斷是否存在num[i]-num[i-1]的質(zhì)數(shù),有的話,就將這個(gè)num[i]減去對應(yīng)的質(zhì)數(shù),

還有個(gè)checksort的函數(shù),判斷是否是嚴(yán)格遞增的,沒錯(cuò)是嚴(yán)格遞增,我以為>=就行了,不行,不行,不行,要>才行啊。。。

綜上就是題意沒理解透徹,另外就是基礎(chǔ)不扎實(shí),還需要多多鍛煉,汗顏啊。。。

Runtime:?6 ms, faster than?90.91%?of?Java?online submissions for?Prime Subtraction Operation.

Memory Usage:?42.6 MB, less than?63.64%?of?Java?online submissions for?Prime Subtraction Operation.


LeetCode 2601. Prime Subtraction Operation的評(píng)論 (共 條)

分享到微博請遵守國家法律
漠河县| 仪陇县| 鸡泽县| 忻州市| 江都市| 永平县| 澄江县| 友谊县| 松桃| 诸城市| 开原市| 都昌县| 枞阳县| 旺苍县| 阜南县| 隆昌县| 手游| 阿克| 五大连池市| 会理县| 扎赉特旗| 定州市| 冷水江市| 九台市| 晋中市| 突泉县| 华坪县| 民权县| 玉门市| 沧州市| 梨树县| SHOW| 剑川县| 闽清县| 枣庄市| 三亚市| 勐海县| 车险| 四川省| 湖口县| 蒙自县|