当前位置:网站首页>Leetcode:162. looking for peak [two points looking for peak]
Leetcode:162. looking for peak [two points looking for peak]
2022-07-24 16:09:00 【White speed Dragon King's review】

analysis
Two points to find the peak , Always go to the higher side , Always reach the peak
Then notice that l <= r or l < r or l < r - 1
ac code
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
n = len(nums)
# People go high , Always reach the peak
def get(i):
if i == -1 or i == n:
return -inf
return nums[i]
l, r, ans = 0, n - 1, -1
while l <= r:
mid = (l + r) // 2
if get(mid - 1) < get(mid) > get(mid + 1):
ans = mid
break
if get(mid) < get(mid + 1):
l = mid + 1
else:
r = mid - 1
return ans
summary
Two points to find the peak
边栏推荐
- G026-db-gs-ins-03 openeuler deployment opengauss (1 active and 2 standby or multiple standby)
- Public and private key transmission, and understanding of CA certificate
- Machine learning notes - building a recommendation system (5) feedforward neural network for collaborative filtering
- Some understanding of the rank sum of matrix and the rank of image
- Leetcode 223. rectangular area
- Image label processing -- converting JSON files into PNG files
- 287 finding duplicates
- 狗牙根植物介绍
- [SWT] scrolling container to realize commodity list style
- Telephone system rules
猜你喜欢

Windows10安装免安装版redis

With this machine learning drawing artifact, papers and blogs can get twice the result with half the effort!

iptables常用命令小清单
![Programming in CoDeSys to realize serial communication [based on raspberry pie 4B]](/img/9c/05118efe2152dc5461a92720732076.jpg)
Programming in CoDeSys to realize serial communication [based on raspberry pie 4B]

Leetcode 231. 2 的幂

聊聊C指针

31 next spread

Kubernetes static storage and dynamic storage

About SQL data query statements
![[adaptiveavgpool3d] pytorch tutorial](/img/d0/60ee74ff554effa06084d5d01a03e1.png)
[adaptiveavgpool3d] pytorch tutorial
随机推荐
Withdrawal of IPO application, Yunzhou intelligent "tour" of unmanned boat enterprise fails to enter the science and Technology Innovation Board
Yolov4 trains its own data set
Rest style
矩阵的秩和图像的秩的一些了解
Leetcode 220. 存在重复元素 III
After data management, the quality is still poor
Mysql8 encountered the problem of stopping after the service was started
C# TCP客户端窗体应用程序异步接收方式
Simplified understanding: publish and subscribe
Lsyncd set up synchronous image - use lsyncd to realize real-time synchronization between local and remote servers
Some understanding of the rank sum of matrix and the rank of image
yolov4 训练自己的数据集
Public and private key transmission, and understanding of CA certificate
Varnish4.0 cache agent configuration
G026-db-gs-ins-03 openeuler deployment opengauss (1 active and 2 standby or multiple standby)
3、 Set foundation ArrayList set and simple student management system
图像label处理——json文件转化为png文件
Replace the image source of Debian full version with Alibaba cloud image source
Urban safety series popular science - enter the high incidence period of drowning, if you know the common sense of life-saving
What is the ranking of good securities companies? Is online account opening safe