Simple easy read version and 1 line python code


  • 0
    Z
    class Solution(object):
        def searchRange(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            if not target in nums:
                return [-1, -1]
            start = nums.index(target)
            time = nums.count(target)
            return [start, start + time - 1]
    

    or just 1 line like this:

    return [-1, 1] if not target in nums else [nums.index(target), nums.index(target) + nums.count(target) - 1]
    

  • 0
    Z
    This post is deleted!

Log in to reply
 

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