Skip to content

Commit e901c3e

Browse files
authored
55.CanJump-贪心算法
1 parent 1a44eea commit e901c3e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CanJump.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public boolean canJump(int[] nums) {
3+
int n = nums.length;
4+
int rightmost = 0;
5+
for (int i = 0; i < n; ++i) {
6+
if (i <= rightmost) {
7+
rightmost = Math.max(rightmost, i + nums[i]);
8+
if (rightmost >= n - 1) {
9+
return true;
10+
}
11+
}
12+
}
13+
return false;
14+
}
15+
}

0 commit comments

Comments
 (0)