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

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

LeetCode 2270. Number of Ways to Split Array

2023-04-13 14:29 作者:您是打尖兒還是住店呢  | 我要投稿

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

nums?contains a?valid split?at index?i?if the following are true:

  • The sum of the first?i + 1?elements is?greater than or equal to?the sum of the last?n - i - 1?elements.

  • There is?at least one?element to the right of?i. That is,?0 <= i < n - 1.

Return?the number of?valid splits?in?nums.

?

Example 1:

Input: nums = [10,4,-8,7]

Output: 2

Explanation: There are three ways of splitting nums into two non-empty parts:?

- Split nums at index 0.?

Then, the first part is [10], and its sum is 10.?

The second part is [4,-8,7], and its sum is 3.?

Since 10 >= 3, i = 0 is a valid split.?


- Split nums at index 1.?

Then, the first part is [10,4], and its sum is 14.?

The second part is [-8,7], and its sum is -1.?

Since 14 >= -1, i = 1 is a valid split.?


- Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6.?

The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split. Thus, the number of valid splits in nums is 2.

Example 2:

Input: nums = [2,3,1,0]

Output: 2

Explanation: There are two valid splits in nums:

- Split nums at index 1. Then, the first part is [2,3], and its sum is 5.?

The second part is [1,0], and its sum is 1.?

Since 5 >= 1, i = 1 is a valid split.?

- Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6.?

The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.

?

典型的pre_sum問(wèn)題,利用前綴和即可。


Constraints:

  • 2 <= nums.length <= 105

  • -105?<= nums[i] <= 105


Runtime:?4 ms, faster than?44.85%?of?Java?online submissions for?Number of Ways to Split Array.

Memory Usage:?59.8 MB, less than?23.68%?of?Java?online submissions for?Number of Ways to Split Array.


LeetCode 2270. Number of Ways to Split Array的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
余姚市| 景德镇市| 辽宁省| 新平| 湟源县| 华亭县| 南木林县| 理塘县| 会同县| 陵水| 安达市| 清丰县| 建阳市| 成都市| 桂林市| 上饶市| 菏泽市| 金溪县| 杨浦区| 南平市| 浮梁县| 平和县| 武夷山市| 乐清市| 金寨县| 分宜县| 偃师市| 河北区| 布拖县| 克山县| 运城市| 南江县| 新民市| 广州市| 康平县| 泉州市| 海伦市| 二连浩特市| 壶关县| 特克斯县| 怀宁县|