Skip to content

Commit d7b6543

Browse files
authored
Create Running Sum of 1d Array
1 parent f5d3252 commit d7b6543

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Running Sum of 1d Array

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int[] runningSum(int[] nums) {
3+
int[] dp = new int[nums.length+1];
4+
int[] res = new int[nums.length];
5+
for(int i = 0; i<nums.length; i++){
6+
dp[i+1] = dp[i] + nums[i];
7+
}
8+
for(int i = 1; i<dp.length; i++){
9+
res[i-1] = dp[i];
10+
}
11+
return res;
12+
}
13+
}

0 commit comments

Comments
 (0)