
maxReach = max(maxReach, nums[i] + i)
Traverse the list once and check what is the max step we can go for each step, we record it as maxReach
Also check if the current position is reachable from any previous step by comparing nums[i] and maxReach
https://github.com/Sylvia-YiyinShen/Algorithm/blob/master/DynamicProgramming/Q055JumpGame.playground/Contents.swift

No comments:
Post a Comment