Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b483cd4

Browse files
feat(LC): add completed 1480 and notes
1 parent f91c204 commit b483cd4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @see {@link https://leetcode.com/problems/running-sum-of-1d-array/description/?envType=study-plan&id=level-1 1480. Running Sum of 1D Array}
3+
*/
4+
5+
/**
6+
* APPROACH
7+
* create an array that will be returned
8+
* create num to store running sum, assign arr[0] starting val
9+
*
10+
* start loop through array
11+
* first num of runSumArr is always arr[0]
12+
* start at run sum two
13+
* get curr num
14+
* add to run sum
15+
* push that sum to arr
16+
* --- next num
17+
* end loop
18+
*
19+
* return runsumarr
20+
*/
21+
22+
/**
23+
* @param {number[]} nums
24+
* @return {number[]}
25+
*/
26+
var runningSum = function (nums) {
27+
// Store first num of nums arr as starting val
28+
let currSum = nums[0];
29+
30+
// Assign first value of return array to currSum
31+
const runSumArr = [currSum];
32+
33+
// Start at SECOND val in loop, if more than one,
34+
// since first sum is just first val
35+
for (let i = 1; i < nums.length; i++) {
36+
const currNum = nums[i];
37+
currSum += currNum;
38+
runSumArr.push(currSum);
39+
}
40+
41+
// Return finished running sum array
42+
return runSumArr;
43+
};
44+
/**
45+
* READ 00:33
46+
* EXPLAIN 03:42 04:15
47+
* APPROACH 03:19 07:34
48+
* CODE 1st Attempt
49+
* TEST
50+
* OPTIMIZE
51+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /