Skip to content

Commit e502446

Browse files
committed
feat: add solutions to lc problem: No.1732
1732.Find the Highest Altitude
1 parent de6fb69 commit e502446

File tree

6 files changed

+155
-4
lines changed

6 files changed

+155
-4
lines changed

solution/1700-1799/1732.Find the Highest Altitude/README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,81 @@
3838
<li><code>-100 <= gain[i] <= 100</code></li>
3939
</ul>
4040

41-
4241
## 解法
4342

4443
<!-- 这里可写通用的实现逻辑 -->
4544

45+
求前 N 项和的最大值即可。
46+
4647
<!-- tabs:start -->
4748

4849
### **Python3**
4950

5051
<!-- 这里可写当前语言的特殊实现逻辑 -->
5152

5253
```python
53-
54+
class Solution:
55+
def largestAltitude(self, gain: List[int]) -> int:
56+
res = t = 0
57+
for h in gain:
58+
t += h
59+
res = max(res, t)
60+
return res
5461
```
5562

5663
### **Java**
5764

5865
<!-- 这里可写当前语言的特殊实现逻辑 -->
5966

6067
```java
68+
class Solution {
69+
public int largestAltitude(int[] gain) {
70+
int res = 0;
71+
int t = 0;
72+
for (int h : gain) {
73+
t += h;
74+
res = Math.max(res, t);
75+
}
76+
return res;
77+
}
78+
}
79+
```
80+
81+
### **C++**
82+
83+
```cpp
84+
class Solution {
85+
public:
86+
int largestAltitude(vector<int>& gain) {
87+
int res = 0, t = 0;
88+
for (int h : gain)
89+
{
90+
t += h;
91+
res = max(res, t);
92+
}
93+
return res;
94+
}
95+
};
96+
```
6197
98+
### **Go**
99+
100+
```go
101+
func largestAltitude(gain []int) int {
102+
res, t := 0, 0
103+
for _, h := range gain {
104+
t += h
105+
res = max(res, t)
106+
}
107+
return res
108+
}
109+
110+
func max(a, b int) int {
111+
if a > b {
112+
return a
113+
}
114+
return b
115+
}
62116
```
63117

64118
### **...**

solution/1700-1799/1732.Find the Highest Altitude/README_EN.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,73 @@
3434
<li><code>-100 &lt;= gain[i] &lt;= 100</code></li>
3535
</ul>
3636

37-
3837
## Solutions
3938

4039
<!-- tabs:start -->
4140

4241
### **Python3**
4342

4443
```python
45-
44+
class Solution:
45+
def largestAltitude(self, gain: List[int]) -> int:
46+
res = t = 0
47+
for h in gain:
48+
t += h
49+
res = max(res, t)
50+
return res
4651
```
4752

4853
### **Java**
4954

5055
```java
56+
class Solution {
57+
public int largestAltitude(int[] gain) {
58+
int res = 0;
59+
int t = 0;
60+
for (int h : gain) {
61+
t += h;
62+
res = Math.max(res, t);
63+
}
64+
return res;
65+
}
66+
}
67+
```
68+
69+
### **C++**
70+
71+
```cpp
72+
class Solution {
73+
public:
74+
int largestAltitude(vector<int>& gain) {
75+
int res = 0, t = 0;
76+
for (int h : gain)
77+
{
78+
t += h;
79+
res = max(res, t);
80+
}
81+
return res;
82+
}
83+
};
84+
```
5185
86+
### **Go**
87+
88+
```go
89+
func largestAltitude(gain []int) int {
90+
res, t := 0, 0
91+
for _, h := range gain {
92+
t += h
93+
res = max(res, t)
94+
}
95+
return res
96+
}
97+
98+
func max(a, b int) int {
99+
if a > b {
100+
return a
101+
}
102+
return b
103+
}
52104
```
53105

54106
### **...**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int largestAltitude(vector<int>& gain) {
4+
int res = 0, t = 0;
5+
for (int h : gain)
6+
{
7+
t += h;
8+
res = max(res, t);
9+
}
10+
return res;
11+
}
12+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func largestAltitude(gain []int) int {
2+
res, t := 0, 0
3+
for _, h := range gain {
4+
t += h
5+
res = max(res, t)
6+
}
7+
return res
8+
}
9+
10+
func max(a, b int) int {
11+
if a > b {
12+
return a
13+
}
14+
return b
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int largestAltitude(int[] gain) {
3+
int res = 0;
4+
int t = 0;
5+
for (int h : gain) {
6+
t += h;
7+
res = Math.max(res, t);
8+
}
9+
return res;
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def largestAltitude(self, gain: List[int]) -> int:
3+
res = t = 0
4+
for h in gain:
5+
t += h
6+
res = max(res, t)
7+
return res

0 commit comments

Comments
 (0)