Have no idea why ii is before i. The solution is to record the max range that one jump can reach and update the bound.
Solution:
# T:O(n) S:O(1) class Solution: # @param {integer[]} nums # @return {integer} def jump(self, nums): last = curr = ret = 0 for i in xrange(len(nums)): if i > last: last = curr ret += 1 curr = max(curr, nums[i]+i) return retRun Time: 68 ms
No comments:
Post a Comment