3432. Count Partitions with Even Sum Difference Easy
1/**
2 * [3432] Count Partitions with Even Sum Difference
3 *
4 * You are given an integer array nums of length n.
5 * A partition is defined as an index i where 0 <= i < n - 1, splitting the array into two non-empty subarrays such that:
6 *
7 * Left subarray contains indices [0, i].
8 * Right subarray contains indices [i + 1, n - 1].
9 *
10 * Return the number of partitions where the difference between the sum of the left and right subarrays is even.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [10,10,3,7,6]</span>
15 * Output: <span class="example-io">4</span>
16 * Explanation:
17 * The 4 partitions are:
18 *
19 * [10], [10, 3, 7, 6] with a sum difference of 10 - 26 = -16, which is even.
20 * [10, 10], [3, 7, 6] with a sum difference of 20 - 16 = 4, which is even.
21 * [10, 10, 3], [7, 6] with a sum difference of 23 - 13 = 10, which is even.
22 * [10, 10, 3, 7], [6] with a sum difference of 30 - 6 = 24, which is even.
23 * </div>
24 * <strong class="example">Example 2:
25 * <div class="example-block">
26 * Input: <span class="example-io">nums = [1,2,2]</span>
27 * Output: <span class="example-io">0</span>
28 * Explanation:
29 * No partition results in an even sum difference.
30 * </div>
31 * <strong class="example">Example 3:
32 * <div class="example-block">
33 * Input: <span class="example-io">nums = [2,4,6,8]</span>
34 * Output: <span class="example-io">3</span>
35 * Explanation:
36 * All partitions result in an even sum difference.
37 * </div>
38 *
39 * Constraints:
40 *
41 * 2 <= n == nums.length <= 100
42 * 1 <= nums[i] <= 100
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/count-partitions-with-even-sum-difference/
48// discuss: https://leetcode.com/problems/count-partitions-with-even-sum-difference/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn count_partitions(nums: Vec<i32>) -> i32 {
54 0
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_3432() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.