일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- DWG
- 컴퓨터의 구조
- LeetCode
- shiba
- Decorator
- t1
- Generator
- Python Implementation
- attribute
- 밴픽
- 파이썬
- Python
- 30. Substring with Concatenation of All Words
- concurrency
- iterator
- data science
- 109. Convert Sorted List to Binary Search Tree
- kaggle
- 시바견
- 715. Range Module
- Class
- Substring with Concatenation of All Words
- Python Code
- Convert Sorted List to Binary Search Tree
- Regular Expression
- 43. Multiply Strings
- 운영체제
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- Protocol
Archives
- Today
- Total
Scribbling
33. Search in Rotated Sorted Array 본문
class Solution:
def search(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums) - 1
while left <= right:
mid = (left + right) // 2
mid_val = nums[mid]
if mid_val == target:
return mid
if nums[mid] >= nums[left]:
if nums[left] <= target < nums[mid]:
right = mid - 1
else:
left = mid + 1
else:
if nums[mid] < target <= nums[right]:
left = mid + 1
else:
right = mid - 1
return -1
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 42. Trapping Rain Water (0) | 2021.09.12 |
---|---|
34. Find First and Last Position of Element in Sorted Array (0) | 2021.09.11 |
LeetCode: 31. Next Permutation (0) | 2021.09.09 |
35. Search Insert Position (0) | 2021.09.08 |
LeetCode: 49. Group Anagrams (0) | 2021.09.08 |