본문 바로가기

두두의 알고리즘/문제

[이분탐색] 릿코드 Medium 33 'Search in Rotated Sorted Array' (Python)

728x90

<문제 링크>

https://leetcode.com/problems/search-in-rotated-sorted-array/

 

Search in Rotated Sorted Array - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com


<문제 풀이>

1. nums에서 target의 인덱스 값을 찾아라

2. target 값이 없으면 -1 

 

<코드>

class Solution:
    def search(self, nums: List[int], target: int) -> int:
        if target in nums:
            return nums.index(target)
        
        return -1