O(n) with python cannot pass testcase91

  • 0

    Is O(n) enough for this question? I cannot find a better algorithm. Could any one tell me if I need a better algorithm, or I need to make my code cleaner, or I just cannot pass this with python. Thank you so much!

    class Solution(object):
        def jump(self, nums):
            length = len(nums)
            if length == 1:
                return 0
            steps = 1
            while(nums[0] + 1 < length):
                steps += 1
                list = nums[1: nums[0] + 1]
                for i in range(nums[0]):
                    list[i] = list[i] + i
                next_i = list.index(max(list)) + 1
                nums = nums[next_i:]
                length = len(nums)
            return steps

Log in to reply

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