일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Convert Sorted List to Binary Search Tree
- Substring with Concatenation of All Words
- Generator
- shiba
- t1
- 시바견
- Python Implementation
- iterator
- 컴퓨터의 구조
- Decorator
- 715. Range Module
- attribute
- concurrency
- Regular Expression
- Protocol
- LeetCode
- 315. Count of Smaller Numbers After Self
- DWG
- kaggle
- Python
- Class
- Python Code
- 30. Substring with Concatenation of All Words
- data science
- 프로그래머스
- 운영체제
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- 43. Multiply Strings
Archives
- Today
- Total
Scribbling
LeetCode: 162. Find Peak Element 본문
Binary Search
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
INT_MAX = int(1e12)
nums = [-INT_MAX] + nums + [-INT_MAX]
def isPeak(idx):
if nums[idx] > nums[idx-1] and nums[idx] > nums[idx+1]:
return True
return False
left, right = 1, len(nums) - 2
while left <= right:
mid = (left + right) // 2
if isPeak(mid):
return mid - 1
if nums[mid-1] > nums[mid]:
right = mid - 1
else:
left = mid + 1
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 172. Factorial Trailing Zeroes (0) | 2021.12.04 |
---|---|
LeetCode: 160. Intersection of Two Linked Lists (0) | 2021.12.02 |
LeetCode: 155. Min Stack (0) | 2021.11.30 |
LeetCode: 152. Maximum Product Subarray (0) | 2021.11.29 |
LeetCode: 134. Gas Station (0) | 2021.11.26 |