Skip to content

Commit 656c1a0

Browse files
authored
Refactored Running Sum of 1d Array.java
1 parent 588a3e1 commit 656c1a0

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Easy/Running Sum of 1d Array.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
class Solution {
22
public int[] runningSum(int[] nums) {
33
int[] ans = new int[nums.length];
4-
int sum = 0;
54
for (int i = 0; i < nums.length; i++) {
6-
sum += nums[i];
7-
ans[i] = sum;
5+
ans[i] = nums[i] + (i == 0 ? 0 : ans[i - 1]);
86
}
97
return ans;
108
}

0 commit comments

Comments
 (0)