최대 1 분 소요

Python

class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        answer = []
        for i in range(len(nums)):
            if nums[i] == target:
                answer.append(i)
        
        if len(answer) == 1:
            answer.append(answer[0])
        if len(answer) > 2:
            return [answer[0], answer[-1]]
        if answer:
            return answer
        else:
            return [-1, -1]

댓글남기기