How to improve this in Python


  • 0
    S

    I have a accepted solution for the question 'search for a range' , anyone have better idea to improve this?

    relist = []
    if target not in nums:
        return [-1,-1]
    else:
        relist.append(nums.index(target))
        relist.append(nums[::-1].index(target))
        if (relist[0]+relist[1]) == (len(nums)-1):
            relist[1]= relist[0]
        else:
            relist[1]= len(nums)-1-nums[::-1].index(target)
    return relist

Log in to reply
 

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