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 3d62b4a

Browse files
committed
commit solution 55
1 parent c09563d commit 3d62b4a

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

‎solution/1-99/0055.jump-game/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [55. 跳跃游戏](https://leetcode-cn.com/problems/jump-game)
22

33
### 题目描述
4-
<!-- 这里写题目描述 -->
4+
55
<p>给定一个非负整数数组,你最初位于数组的第一个位置。</p>
66

77
<p>数组中的每个元素代表你在该位置可以跳跃的最大长度。</p>
@@ -26,15 +26,28 @@
2626

2727
### 解题思路
2828

29+
1. 贪心算法
2930

3031
### 具体解法
3132

32-
<!-- tabs:start -->
3333

3434
#### **Golang**
3535
```go
36-
36+
func canJump(nums []int) bool {
37+
if len(nums) == 0 {
38+
return false
39+
}
40+
max := 0
41+
for i := 0; i <= max; i++ {
42+
if i+nums[i] > max {
43+
max = i + nums[i]
44+
}
45+
if max >= len(nums)-1 {
46+
return true
47+
}
48+
}
49+
return false
50+
}
3751
```
3852

39-
<!-- tabs:end -->
4053

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package leetcode
2+
3+
/*
4+
* @lc app=leetcode.cn id=55 lang=golang
5+
*
6+
* [55] 跳跃游戏
7+
*/
8+
9+
// @lc code=start
10+
func canJump(nums []int) bool {
11+
if len(nums) == 0 {
12+
return false
13+
}
14+
max := 0
15+
for i := 0; i <= max; i++ {
16+
if i+nums[i] > max {
17+
max = i + nums[i]
18+
}
19+
if max >= len(nums)-1 {
20+
return true
21+
}
22+
}
23+
return false
24+
}
25+
26+
// @lc code=end

‎solution/1-99/_sidebar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [1 - 99题](index-tags.md)
99
- [1. 两数之和 ✅](solution/1-99/0001.two-sum/)
1010
- [2. 两数相加 ✅](solution/1-99/0002.add-two-numbers/)
11-
- [3. 无重复字符的最长子串](solution/1-99/0003.longest-substring-without-repeating-characters/)
11+
- [3. 无重复字符的最长子串](solution/1-99/0003.longest-substring-without-repeating-characters/)
1212
- [4. 寻找两个有序数组的中位数](solution/1-99/0004.median-of-two-sorted-arrays/)
1313
- [5. 最长回文子串](solution/1-99/0005.longest-palindromic-substring/)
1414
- [6. z 字形变换](solution/1-99/0006.zigzag-conversion/)
@@ -60,7 +60,7 @@
6060
- [52. n皇后 ii](solution/1-99/0052.n-queens-ii/)
6161
- [53. 最大子序和 ✅](solution/1-99/0053.maximum-subarray/)
6262
- [54. 螺旋矩阵](solution/1-99/0054.spiral-matrix/)
63-
- [55. 跳跃游戏](solution/1-99/0055.jump-game/)
63+
- [55. 跳跃游戏](solution/1-99/0055.jump-game/)
6464
- [56. 合并区间 ✅](solution/1-99/0056.merge-intervals/)
6565
- [57. 插入区间](solution/1-99/0057.insert-interval/)
6666
- [58. 最后一个单词的长度 ✅](solution/1-99/0058.length-of-last-word/)

0 commit comments

Comments
(0)

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