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