1480. Running Sum of 1d Array Easy
1/**
2 * [1480] Running Sum of 1d Array
3 *
4 * Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).
5 *
6 * Return the running sum of nums.
7 *
8 *
9 * Example 1:
10 *
11 *
12 * Input: nums = [1,2,3,4]
13 * Output: [1,3,6,10]
14 * Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
15 *
16 * Example 2:
17 *
18 *
19 * Input: nums = [1,1,1,1,1]
20 * Output: [1,2,3,4,5]
21 * Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
22 *
23 * Example 3:
24 *
25 *
26 * Input: nums = [3,1,2,10,1]
27 * Output: [3,4,6,16,17]
28 *
29 *
30 *
31 * Constraints:
32 *
33 *
34 * 1 <= nums.length <= 1000
35 * -10^6 <= nums[i] <= 10^6
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/running-sum-of-1d-array/
41// discuss: https://leetcode.com/problems/running-sum-of-1d-array/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn running_sum(nums: Vec<i32>) -> Vec<i32> {
47
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_1480() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.