Advertisement
ogv

Untitled

ogv
Aug 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. /*
  2. Runtime: 1 ms, faster than 99.26% of Java online submissions for Jump Game.
  3. Memory Usage: 36.1 MB, less than 100.00% of Java online submissions for Jump Game.
  4. */
  5. class Solution {
  6.     public boolean canJump(int[] nums) {
  7.         int len = nums.length;
  8.         if (len == 0) return false;
  9.         if (len == 1) return true;
  10.        
  11.         int maxVisited = 0;
  12.        
  13.         for (int i = 0; i <= maxVisited; i++) {            
  14.             maxVisited = Math.max(maxVisited, i + nums[i]);
  15.            
  16.             if (maxVisited >= len - 1) {
  17.                 return true;
  18.             }                    
  19.         }
  20.        
  21.         return false;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement