Simple Python solution using dictionary


  • 0
    G
    class Solution(object):
        def searchRange(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            a={}
            if len(nums)==0:
                return [-1,-1]
            for i in range(len(nums)):
                if nums[i]==target:
                    a[i]=i
            b=a.keys()
            b.sort()
            if len(b)>0:
                return [b[0],b[-1]]
            else:
                return [-1,-1]

Log in to reply
 

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