Skip to content

Commit e601f6f

Browse files
Create running-sum-of-1d-array.java
1 parent b31520a commit e601f6f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: Java/running-sum-of-1d-array.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Running Sum of 1d Array
3+
*
4+
* Time Complexity - O(n)
5+
* Space Complexity - O(n)
6+
*
7+
* Runtime: 0 ms, faster than 100.00% of Java online submissions
8+
*/
9+
class Solution {
10+
public int[] runningSum(int[] nums) {
11+
12+
int len = nums.length;
13+
int[] runningSumAr = new int[len];
14+
15+
int sumSoFar = 0;
16+
17+
for(int i=0; i<len; i++){
18+
sumSoFar += nums[i];
19+
20+
runningSumAr[i] = sumSoFar;
21+
}
22+
23+
return runningSumAr;
24+
}
25+
}

0 commit comments

Comments
 (0)