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