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