Home >Java >javaTutorial >Running Sum of Array
Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).
Return the running sum of nums.
Example 1:
Example 2:
Example 3:
Constraints:
class Solution {
public int[] runningSum(int[] nums) {
int[] output = new int[nums.length];
output[0] = nums[0];
for(int i = 1; i
System.out.println(output[i]);
}
return output;
}
}
class Solution {
public int[] runningSum(int[] nums) {
for (int i= 1; i < nums.length; i ) {
nums[i] = nums[i - 1];
System.out.println(nums[i]);
};
return nums;
}
}
The above is the detailed content of Running Sum of Array. For more information, please follow other related articles on the PHP Chinese website!