일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Decorator
- 프로그래머스
- Python Implementation
- 315. Count of Smaller Numbers After Self
- concurrency
- shiba
- Substring with Concatenation of All Words
- Protocol
- 시바견
- 30. Substring with Concatenation of All Words
- attribute
- iterator
- Python Code
- 파이썬
- 컴퓨터의 구조
- data science
- Generator
- t1
- Regular Expression
- 운영체제
- 밴픽
- kaggle
- 715. Range Module
- LeetCode
- 43. Multiply Strings
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- Python
- Class
Archives
- Today
- Total
Scribbling
LeetCode: 81. Search in Rotated Sorted Array II 본문
Computer Science/Coding Test
LeetCode: 81. Search in Rotated Sorted Array II
focalpoint 2021. 10. 6. 15:09이 문제는 아래 문제와 상당히 유사하다.
33. Search in Rotated Sorted Array (https://leetcode.com/problems/search-in-rotated-sorted-array/description/)
실제 구현도 유사하지만, Time Complexity는 다른데 그 이유를 생각해보면 흥미롭다.
class Solution:
def search(self, nums: List[int], target: int) -> bool:
left, right = 0, len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return True
if nums[mid] < nums[right]:
if nums[mid] < target <= nums[right]:
left = mid + 1
else:
right = mid - 1
elif nums[mid] > nums[right]:
if nums[left] <= target < nums[mid]:
right = mid - 1
else:
left = mid + 1
else:
return target in nums[left:right+1]
return False
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 86. Partition List (0) | 2021.10.06 |
---|---|
LeetCode: 82. Remove Duplicates from Sorted List II (0) | 2021.10.06 |
LeetCode: 80. Remove Duplicates from Sorted Array II (0) | 2021.10.06 |
LeetCode: 84. Largest Rectangle in Histogram (0) | 2021.10.04 |
LeetCode: 85. Maximal Rectangle (0) | 2021.10.04 |