45. Jump Game II

xiaoxiao2021-02-27  131

class Solution(object):     def jump(self, nums):         """         :type nums: List[int]         :rtype: int         """         n, start, end, step = len(nums), 0, 0, 0         while end < n - 1:             step += 1             maxend = end + 1             for i in range(start, end + 1):                 if i + nums[i] >= n - 1:                     return step                 maxend = max(maxend, i + nums[i])             start, end = end + 1, maxend

        return step

https://discuss.leetcode.com/topic/18815/10-lines-c-16ms-python-bfs-solutions-with-explanations

转载请注明原文地址: https://www.6miu.com/read-16516.html

最新回复(0)