LeetCode - Running Sum of 1d Array Solution - The Coding Shala
Home >> LeetCode >> running sum of 1d array
In this post, we will learn how to solve LeetCode's Running Sum of 1d Array problem and its solution in Java.
Running Sum of 1d Array
Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums…nums[i]). Return the running sum of nums.
Input: nums = [1,2,3,4]
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
Running Sum of 1d Array Java Solution
Creating a new Array. consider given array is A and we will create a new Array B then:
B[i] = A + A + .... + A[i] or or we can write as B[i] = A[i] + B[i-1].
We can modify the same array.
Other Posts You May Like
- LeetCode - Next greater element
- LeetCode - Climbing stairs
- LeetCode - swap nodes
- LeetCode - degree of an array
- LeetCode - contains duplicate