Created
October 30, 2020 20:17
-
-
Save TechWithTy/68d1519cc952a53879b4d9b17d470ae9 to your computer and use it in GitHub Desktop.
Running sum O(n) Leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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