A simple Python solution


  • 0
    T
    class Solution(object):
        def searchRange(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            list=[]
    
            for i,value in enumerate(nums):
                if value==target:
                    list.append(i)
    
            if len(list)==0:
                return [-1,-1]
            elif len(list)==1:
                return [list[0],list[0]]
            else:
                return [list[0],list[len(list)-1]]

Log in to reply
 

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