| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Tags
- Convert Sorted List to Binary Search Tree
- Generator
- attribute
- data science
- Python
- 43. Multiply Strings
- Python Code
- kaggle
- Class
- Substring with Concatenation of All Words
- 시바견
- Regular Expression
- Python Implementation
- DWG
- 109. Convert Sorted List to Binary Search Tree
- Decorator
- 315. Count of Smaller Numbers After Self
- LeetCode
- shiba
- concurrency
- 715. Range Module
- iterator
- t1
- 프로그래머스
- 밴픽
- 운영체제
- 파이썬
- 컴퓨터의 구조
- 30. Substring with Concatenation of All Words
- 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 |