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