/**
*
* Ashish Patel
* e: ashishsushilPatel@gmail.com
* w: https://ashish.me
*
*/
function TreeNode(val) {
this.val = val
this.left = this.right = null
}
const runningSumOf1DArray = nums => {
let result = []
const helper = (nums, index, sum) => {
if (nums.length == index) {
return
}
result[index] = sum + nums[index]
helper(nums, index + 1, sum + nums[index])
}
helper(nums, 0, 0)
return result
}
test('runningSumOf1DArray', () => {
expect(runningSumOf1DArray([1, 2, 3, 4])).toEqual([1, 3, 6, 10])
})
Created 2021-01-31T09:12:13+05:30, updated 2021-01-31T10:03:49+05:30 · History · Edit