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

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

LeetCode 2811. Check if it is Possible to Split Array

2023-08-10 12:43 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an array?nums?of length?n?and an integer?m. You need to determine if it is possible to split the array into?n?non-empty?arrays by performing a series of steps.

In each step, you can select an existing array (which may be the result of previous steps) with a length of?at least two?and split it into?two?subarrays, if,?for each?resulting subarray,?at least?one of the following holds:

  • The length of the subarray is one, or

  • The sum of elements of the subarray is?greater than or equal?to?m.

Return?true?if you can split the given array into?n?arrays, otherwise return?false.

Note:?A subarray is?a contiguous non-empty sequence of elements within an array.

?

Example 1:

Input: nums = [2, 2, 1], m = 4

Output: true

Explanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.

Example 2:

Input: nums = [2, 1, 3], m = 5?

Output: false

Explanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.

Example 3:

Input: nums = [2, 3, 3, 2, 3], m = 6

Output: true

Explanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.

?

Constraints:

  • 1 <= n == nums.length <= 100

  • 1 <= nums[i] <= 100

  • 1 <= m <= 200

-----------------------------------

給你一個(gè)長(zhǎng)度為?n?的數(shù)組?nums?和一個(gè)整數(shù)?m?。請(qǐng)你判斷能否執(zhí)行一系列操作,將數(shù)組拆分成?n?個(gè)?非空?數(shù)組。

在每一步操作中,你可以選擇一個(gè)?長(zhǎng)度至少為 2?的現(xiàn)有數(shù)組(之前步驟的結(jié)果) 并將其拆分成?2?個(gè)子數(shù)組,而得到的?每個(gè)?子數(shù)組,至少?需要滿足以下條件之一:

  • 子數(shù)組的長(zhǎng)度為 1 ,或者

  • 子數(shù)組元素之和?大于或等于??m?。

如果你可以將給定數(shù)組拆分成?n?個(gè)滿足要求的數(shù)組,返回?true?;否則,返回?false?。

注意:子數(shù)組是數(shù)組中的一個(gè)連續(xù)非空元素序列。

--------------------------------

只要能夠找到一組值,他們的和是大于等于m的話,就可以的。

下面是代碼:


Runtime:?1 ms, faster than?99.50%?of?Java?online submissions for?Check if it is Possible to Split Array.

Memory Usage:?42.7 MB, less than?88.63%?of?Java?online submissions for?Check if it is Possible to Split Array.


LeetCode 2811. Check if it is Possible to Split Array的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
平舆县| 习水县| 监利县| 平阴县| 台前县| 德阳市| 集贤县| 三台县| 威宁| 抚宁县| 建湖县| 日照市| 尼木县| 二连浩特市| 罗定市| 南靖县| 佛山市| 西乌珠穆沁旗| 敦煌市| 噶尔县| 泰州市| 清苑县| 永寿县| 铜山县| 二连浩特市| 兴和县| 仁寿县| 黑山县| 疏勒县| 澳门| 华池县| 崇信县| 五原县| 嘉祥县| 合作市| 建德市| 淄博市| 颍上县| 九寨沟县| 婺源县| 莆田市|