Running Sum of 1d Array
July 27, 2020
Running Sum of 1d Array
class Solution {
public int[] runningSum(int[] nums) {
int beforeNum = 0;
for (int i = 0; i < nums.length; i++) {
nums[i] = nums[i] + beforeNum;
beforeNum = nums[i];
}
return nums;
}
}
Temporary save the previous array value and added it.