File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,43 @@ List is periodically updated
44
55## LeetCode
66
7+ ### #724 . Find Pivot Index
8+
9+ ```
10+ let pivotIndex = function(nums) {
11+ if (nums.length === 0 ) return 1
12+ if (nums.length === 1 ) return 0
13+
14+ let sum = nums.reduce((a,b) => a + b);
15+ let leftSum = 0;
16+
17+ for (let i = 0; i < nums.length; i++){
18+ if (leftSum === sum - nums[i] - leftSum){
19+ return i
20+ }
21+ leftSum += nums[i]
22+ }
23+
24+ return -1
25+ };
26+
27+ ```
28+
729
30+ ### #1480 . Running Sum of 1d Array
31+
32+ ```
33+ let runningSum = function(nums) {
34+ let arr = [nums[0]];
35+ for(let i = 1; i < nums.length; i++){
36+ let sum = nums.slice(0, i+1)
37+ arr.push(sum.reduce((a, b) => a + b))
38+ }
39+ return arr
40+ };
41+ ```
42+
43+
844 ### #118 . Pascal's Triangle
945
1046```
You can’t perform that action at this time.
0 commit comments