Concise Python O(n) Greedy BFS


  • 0
        def jump(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            cnt = i = mx = 0
            while mx < len(nums)-1:
                mn = mx + 1
                for val in range(i, mx+1):
                    mx = max(mx, nums[val] + val)
                i = mn
                cnt += 1
            return cnt
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.