Skip to content

Instantly share code, notes, and snippets.

@TechWithTy
Created October 30, 2020 20:17
Show Gist options
  • Save TechWithTy/68d1519cc952a53879b4d9b17d470ae9 to your computer and use it in GitHub Desktop.
Save TechWithTy/68d1519cc952a53879b4d9b17d470ae9 to your computer and use it in GitHub Desktop.
Running sum O(n) Leetcode
/**
* @param {number[]} nums
* @return {number[]}
*/
var runningSum = function(nums) {
let newNums = [];
let numsSum = 0;
nums.forEach((num,i) =>{
if(nums[i] !== null){
numsSum += nums[i]
newNums.push(numsSum)
}
})
return newNums;
};
//O(n) runs through array once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment