Solution 1: TLE
Normal DP.
Time: O(nk) (k is the largest input[i])
Space: O(n)
|
|
Solution 2: accepted 10ms
DP.
Time: O(n)
Space: O(1)
|
|
Solution 3: accepted 8ms
7ms123456789public boolean canJump(int[] nums) { int last = nums.length - 1; for (int i = nums.length - 2; i >= 0; i--) { if (i + nums[i] >= last) { last = i; } } return last == 0;}
8ms12345678910public boolean canJump(int[] nums) { int len = nums.length; int last = len - 1; for (int i = len - 2; i >= 0; i--) { if (i + nums[i] >= last) { last = i; } } return last == 0;}