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