Skip to content

Commit 58d9812

Browse files
authored
Create 55. Jump Game
1 parent 704a467 commit 58d9812

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

55. Jump Game

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public boolean canJump(int[] nums) {
3+
int n = nums.length;
4+
5+
if(n==1) return true;
6+
7+
int max = 0;
8+
9+
for(int index=0;index<n-1 && max>=index;index++){
10+
if(max<index+nums[index]){
11+
max = index + nums[index];
12+
}
13+
14+
if(max>=n-1){
15+
return true;
16+
}
17+
}
18+
19+
return false;
20+
}
21+
}

0 commit comments

Comments
 (0)