Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 699b1ec

Browse files
✨feat: add 1732
1 parent a17d5ee commit 699b1ec

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

‎Index/模拟.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
| [1716. 计算力扣银行的钱](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-ifit/) | 简单 | 🤩🤩🤩🤩 |
204204
| [1720. 解码异或后的数组](https://leetcode-cn.com/problems/decode-xored-array/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/decode-xored-array/solution/gong-shui-san-xie-li-yong-yi-huo-xing-zh-p1bi/) | 简单 | 🤩🤩🤩 |
205205
| [1725. 可以形成最大正方形的矩形数目](https://leetcode-cn.com/problems/number-of-rectangles-that-can-form-the-largest-square/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/number-of-rectangles-that-can-form-the-largest-square/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-7756/) | 简单 | 🤩🤩🤩🤩 |
206+
| [1732. 找到最高海拔](https://leetcode.cn/problems/find-the-highest-altitude/) | [LeetCode 题解链接](https://leetcode.cn/problems/find-the-highest-altitude/solution/by-ac_oier-a0j8/) | 简单 | 🤩🤩🤩🤩 |
206207
| [1736. 替换隐藏数字得到的最晚时间](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/solution/gong-shui-san-xie-ti-huan-yin-cang-shu-z-2l1h/) | 简单 | 🤩🤩🤩🤩 |
207208
| [1737. 满足三条件之一需改变的最少字符数](https://leetcode.cn/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/) | [LeetCode 题解链接](https://leetcode.cn/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/solution/by-ac_oier-vs5u/) | 中等 | 🤩🤩🤩🤩 |
208209
| [1743. 从相邻元素对还原数组](https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs/solution/gong-shui-san-xie-yi-ti-shuang-jie-dan-x-elpx/) | 中等 | 🤩🤩🤩🤩 |
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[1732. 找到最高海拔](https://leetcode.cn/problems/find-the-highest-altitude/solution/by-ac_oier-a0j8/)** ,难度为 **简单**
4+
5+
Tag : 「模拟」
6+
7+
8+
9+
有一个自行车手打算进行一场公路骑行,这条路线总共由 $n + 1$ 个不同海拔的点组成。自行车手从海拔为 `0` 的点 `0` 开始骑行。
10+
11+
给你一个长度为 `n` 的整数数组 `gain`,其中 `gain[i]` 是点 `i` 和点 `i + 1` 的 净海拔高度差(0ドル <= i < n$)。请你返回 最高点的海拔 。
12+
13+
示例 1:
14+
```
15+
输入:gain = [-5,1,5,0,-7]
16+
17+
输出:1
18+
19+
解释:海拔高度依次为 [0,-5,-4,1,1,-6] 。最高海拔为 1 。
20+
```
21+
示例 2:
22+
```
23+
输入:gain = [-4,-3,-2,-1,4,3,2]
24+
25+
输出:0
26+
27+
解释:海拔高度依次为 [0,-4,-7,-9,-10,-6,-3,-1] 。最高海拔为 0 。
28+
```
29+
30+
提示:
31+
* $n = gain.length$
32+
* 1ドル <= n <= 100$
33+
* $-100 <= gain[i] <= 100$
34+
35+
---
36+
37+
### 模拟
38+
39+
根据题意进行模拟即可。
40+
41+
Java 代码:
42+
```Java
43+
class Solution {
44+
public int largestAltitude(int[] g) {
45+
int cur = 0, ans = 0;
46+
for (int x : g) {
47+
cur += x;
48+
ans = Math.max(ans, cur);
49+
}
50+
return ans;
51+
}
52+
}
53+
```
54+
TypeScript 代码:
55+
```TypeScript
56+
function largestAltitude(g: number[]): number {
57+
let cur = 0, ans = 0
58+
for (let x of g) {
59+
cur += x
60+
ans = Math.max(ans, cur)
61+
}
62+
return ans
63+
}
64+
```
65+
Python3 代码:
66+
```Python3
67+
class Solution:
68+
def largestAltitude(self, g: List[int]) -> int:
69+
cur, ans = 0, 0
70+
for x in g:
71+
cur += x
72+
ans = max(ans, cur)
73+
return ans
74+
```
75+
* 时间复杂度:$O(n)$
76+
* 空间复杂度:$O(1)$
77+
78+
---
79+
80+
### 最后
81+
82+
这是我们「刷穿 LeetCode」系列文章的第 `No.1732` 篇,系列开始于 2021年01月01日,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
83+
84+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
85+
86+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
87+
88+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
89+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /