We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 588a3e1 commit 656c1a0Copy full SHA for 656c1a0
Easy/Running Sum of 1d Array.java
@@ -1,10 +1,8 @@
1
class Solution {
2
public int[] runningSum(int[] nums) {
3
int[] ans = new int[nums.length];
4
- int sum = 0;
5
for (int i = 0; i < nums.length; i++) {
6
- sum += nums[i];
7
- ans[i] = sum;
+ ans[i] = nums[i] + (i == 0 ? 0 : ans[i - 1]);
8
}
9
return ans;
10
0 commit comments