simple and clean python solution


  • 0
    X
    class Solution(object):
        def searchRange(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            lst = []
            lst1 = []
            c = 0
            if target in nums:
                for i in range(len(nums)):
                    c+=1
                    if nums[i] == target:
                        lst.append(i)
                        break
                for k in range(i+1,len(nums)):
                    lst1.append(nums[k])
                if target in lst1:
                    for j in range(len(lst1)):
                        if lst1[j] != target:
                            lst.append(j-1+c)
                            break
                    if len(lst)==1:
                        lst.append(len(nums)-1)
                        return lst
                    else:
                        return lst
                else:
                    lst.append(lst[0])
                    return lst
            else:
                return [-1,-1]
    

Log in to reply
 

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