My Python code gives the right answer while OJ returns the IndexError that list out of range with input [3,2,1]?

  • 1
    class Solution:
    # @param nums, an integer[]
    # @return an integer
        def search(self, nums, start, end):
            if start == end:
                return start
            if start + 1 == end:
                return start if nums[start] > nums[end] else end
            mid = (start + end) / 2
            if nums[mid] < nums[mid-1]:
                return, start, mid-1)
            if nums[mid] < nums[mid+1]:
                return, mid+1, end)
            return mid
        def findPeakElement(self, nums):
            return, 0, len(nums)-1)

  • 0

    I got the same error.
    Line 39: IndexError: list index out of range

Log in to reply

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