8000 Update README.md · abroroo/leetcode@f676b6d · GitHub
[go: up one dir, main page]

Skip to content

Commit f676b6d

Browse files
authored
Update README.md
1 parent 6e8928f commit f676b6d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff 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
```

0 commit comments

Comments
 (0)
0