Skip to content

Commit 5533c05

Browse files
committed
✅ [1732] too ez...
1 parent 3cae0cc commit 5533c05

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

1732/my_solution.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {number[]} gain
3+
* @return {number}
4+
*/
5+
const largestAltitude = (gain) => {
6+
let max = 0, acc = 0
7+
8+
for (let i = 0; i < gain.length; i++) {
9+
acc += gain[i]
10+
max = Math.max(max, acc)
11+
}
12+
13+
return max;
14+
};
15+
16+
// /**
17+
// * @param {number[]} gain
18+
// * @return {number}
19+
// */
20+
// const largestAltitude = (gain) => {
21+
// let max = 0, tmpMax = 0;
22+
// for (let i = 0; i < gain.length; i++) {
23+
// tmpMax += gain[i];
24+
// max = Math.max(max, tmpMax);
25+
// }
26+
// return max;
27+
// };

1732/solution.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number[]} gain
3+
* @return {number}
4+
*/
5+
const largestAltitude = (gain) => {
6+
let max = 0, tmpMax = 0;
7+
for (let i = 0; i < gain.length; i++) {
8+
tmpMax += gain[i];
9+
max = Math.max(max, tmpMax);
10+
}
11+
return max;
12+
};

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
- [1572. Matrix Diagonal Sum](./1572/)
113113
- [1672. Richest Customer Wealth](./1672/)
114114
- [1679. Max Number of K-Sum Pairs](./1679/)
115+
- [1732. Find the Highest Altitude](./1732/)
115116
- [1768. Merge Strings Alternately](./1768/)
116117
- [1791. Find Center of Star Graph](./1791/)
117118
- [1909. Remove One Element to Make the Array Strictly Increasing](./1909/)
@@ -166,7 +167,7 @@ Batch create:
166167
NOTE: JS IS HERE
167168
-->
168169
```ssh
169-
chapter=1493 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
170+
chapter=1732 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
170171
```
171172
> then you can use `x` for quick debug.
172173

0 commit comments

Comments
 (0)