Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Runtime: 1 ms, faster than 99.26% of Java online submissions for Jump Game.
- Memory Usage: 36.1 MB, less than 100.00% of Java online submissions for Jump Game.
- */
- class Solution {
- public boolean canJump(int[] nums) {
- int len = nums.length;
- if (len == 0) return false;
- if (len == 1) return true;
- int maxVisited = 0;
- for (int i = 0; i <= maxVisited; i++) {
- maxVisited = Math.max(maxVisited, i + nums[i]);
- if (maxVisited >= len - 1) {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement