2574. Left and Right Sum Differences Easy
1/**
2 * [2574] Left and Right Sum Differences
3 *
4 * Given a 0-indexed integer array nums, find a 0-indexed integer array answer where:
5 *
6 * answer.length == nums.length.
7 * answer[i] = |leftSum[i] - rightSum[i]|.
8 *
9 * Where:
10 *
11 * leftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.
12 * rightSum[i] is the sum of elements to the right of the index i in the array nums. If there is no such element, rightSum[i] = 0.
13 *
14 * Return the array answer.
15 *
16 * <strong class="example">Example 1:
17 *
18 * Input: nums = [10,4,8,3]
19 * Output: [15,1,11,22]
20 * Explanation: The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0].
21 * The array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].
22 *
23 * <strong class="example">Example 2:
24 *
25 * Input: nums = [1]
26 * Output: [0]
27 * Explanation: The array leftSum is [0] and the array rightSum is [0].
28 * The array answer is [|0 - 0|] = [0].
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= nums.length <= 1000
34 * 1 <= nums[i] <= 10^5
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/left-and-right-sum-differences/
40// discuss: https://leetcode.com/problems/left-and-right-sum-differences/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn left_right_difference(nums: Vec<i32>) -> Vec<i32> {
46 vec![]
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2574() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.