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 5ec246b

Browse files
solves jump game
1 parent 5995bda commit 5ec246b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | |
4848
| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | |
4949
| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | |
50+
| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | |
5051
| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | |
5152
| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | |
5253
| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | |

‎src/JumpGame.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://leetcode.com/problems/jump-game
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class JumpGame {
6+
public boolean canJump(int[] nums) {
7+
int last = nums.length - 1;
8+
for (int i = nums.length - 2 ; i >= 0 ; i--) {
9+
if (i + nums[i] >= last) last = i;
10+
}
11+
return last == 0;
12+
}
13+
}

0 commit comments

Comments
(0)

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