11---
2- title : 1732.找到最高海拔
2+ title : 1732.找到最高海拔:模拟
33date : 2022-11-19 08:33:19
44tags : [题解, LeetCode, 简单, 数组, 前缀和, 模拟]
55categories : [题解, LeetCode]
66---
77
8- # 【LetMeFly】1732.找到最高海拔
8+ # 【LetMeFly】1732.找到最高海拔:模拟
99
1010力扣题目链接:[ https://leetcode.cn/problems/find-the-highest-altitude/ ] ( https://leetcode.cn/problems/find-the-highest-altitude/ )
1111
@@ -59,6 +59,9 @@ categories: [题解, LeetCode]
5959#### C++
6060
6161``` cpp
62+ /*
63+ * @LastEditTime: 2022-11-19 08:30:56
64+ */
6265class Solution {
6366public:
6467 int largestAltitude(vector<int >& gain) {
@@ -73,5 +76,78 @@ public:
7376};
7477```
7578
79+ #### Python
80+
81+ ```python
82+ '''
83+ LastEditTime: 2026-06-19 10:19:06
84+ '''
85+ from typing import List
86+
87+ class Solution:
88+ def largestAltitude(self, gain: List[int]) -> int:
89+ ans = now = 0
90+ for t in gain:
91+ now += t
92+ ans = max(ans, now)
93+ return ans
94+
95+ ```
96+
97+ #### Java
98+
99+ ``` java
100+ /*
101+ * @LastEditTime: 2026-06-19 10:18:18
102+ */
103+ class Solution {
104+ public int largestAltitude (int [] gain ) {
105+ int ans = 0 , now = 0 ;
106+ for (int t : gain) {
107+ now += t;
108+ ans = Math . max(ans, now);
109+ }
110+ return ans;
111+ }
112+ }
113+ ```
114+
115+ #### Go
116+
117+ ``` go
118+ /*
119+ * @LastEditTime: 2026-06-19 10:17:13
120+ */
121+ package main
122+
123+ func largestAltitude (gain []int ) (ans int ) {
124+ now := 0
125+ for _ , t := range gain {
126+ now += t
127+ ans = max (ans, now)
128+ }
129+ return
130+ }
131+ ```
132+
133+ #### Rust
134+
135+ ``` rust
136+ /*
137+ * @LastEditTime: 2026-06-19 10:19:43
138+ */
139+ impl Solution {
140+ pub fn largest_altitude (gain : Vec <i32 >) -> i32 {
141+ let mut ans = 0 ;
142+ let mut now = 0 ;
143+ for t in gain . iter () {
144+ now += t ;
145+ ans = ans . max (now );
146+ }
147+ ans
148+ }
149+ }
150+ ```
151+
76152> 同步发文于CSDN ,原创不易,转载请附上[原文链接](https:// blog.letmefly.xyz/2022/11/19/LeetCode%201732.%E6%89%BE%E5%88%B0%E6%9C%80%E9%AB%98%E6%B5%B7%E6%8B%94/)哦~
77153> Tisfy:[https:// letmefly.blog.csdn.net/article/details/127932334](https://letmefly.blog.csdn.net/article/details/127932334)
0 commit comments