|
1 | 1 | # [2270.Number of Ways to Split Array][title]
|
2 | 2 |
|
3 |
| -> [!WARNING|style:flat] |
4 |
| -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 |
| -
|
6 | 3 | ## Description
|
7 | 4 |
|
| 5 | +You are given a **0-indexed** integer array `nums` of length `n`. |
| 6 | + |
| 7 | +`nums` contains a **valid split** at index `i` if the following are true: |
| 8 | + |
| 9 | +- The sum of the first `i + 1` elements is **greater than or equal to** the sum of the last `n - i - 1` elements. |
| 10 | +- There is **at least one** element to the right of `i`. That is, `0 <= i < n - 1`. |
| 11 | + |
| 12 | +Return the number of **valid splits** in `nums`. |
| 13 | + |
8 | 14 | **Example 1:**
|
9 | 15 |
|
10 | 16 | ```
|
11 |
| -Input: a = "11", b = "1" |
12 |
| -Output: "100" |
| 17 | +Input: nums = [10,4,-8,7] |
| 18 | +Output: 2 |
| 19 | +Explanation: |
| 20 | +There are three ways of splitting nums into two non-empty parts: |
| 21 | +- 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. |
| 22 | +- 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. |
| 23 | +- 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. |
| 24 | +Thus, the number of valid splits in nums is 2. |
13 | 25 | ```
|
14 | 26 |
|
15 |
| -## 题意 |
16 |
| -> ... |
17 |
| -
|
18 |
| -## 题解 |
| 27 | +**Example 2:** |
19 | 28 |
|
20 |
| -### 思路1 |
21 |
| -> ... |
22 |
| -Number of Ways to Split Array |
23 |
| -```go |
24 | 29 | ```
|
25 |
| - |
| 30 | +Input: nums = [2,3,1,0] |
| 31 | +Output: 2 |
| 32 | +Explanation: |
| 33 | +There are two valid splits in nums: |
| 34 | +- 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. |
| 35 | +- 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. |
| 36 | +``` |
26 | 37 |
|
27 | 38 | ## 结语
|
28 | 39 |
|
|
0 commit comments