当前位置:网站首页>LeetCode 162.寻找峰值(中等)
LeetCode 162.寻找峰值(中等)
2022-08-10 05:32:00 【生信研究猿】
python
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
if(len(nums)==1):
return 0
if(nums[0]>nums[1]):
return 0
if(nums[len(nums)-1]>nums[len(nums)-2]):
return len(nums)-1
'''
复杂度O(n)
i = 1
while(1):
if(nums[i]>nums[i-1] and nums[i]>nums[i+1]):
break
i +=1
return i
'''
#二分法
left = 0
right = len(nums)-1
while(left<right):
mid = int((left + right )/2)
if(nums[mid]>nums[mid+1]):
right = mid
else:
left = mid +1
return left

边栏推荐
猜你喜欢

Day1 微信小程序-小程序代码的构成

ORACLE system table space SYSTEM is full and cannot expand table space problem solving process

Multi-table query Notes

The latest and most complete digital collection sales calendar-07.26

pytorch-09.多分类问题

MySql 约束

菜谱小程序源码免费分享【推荐】

Collection工具类

IO stream【】【】【】

LeetCode 剑指offer 21.调整数组顺序使奇数位于偶数前面(简单)
随机推荐
String common methods
去中心化和p2p网络以及中心化为核心的传统通信
opencv
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
小程序wx.request简单Promise封装
第二次实验
力扣——统计只差一个字符的子串数目
Day1 微信小程序-小程序代码的构成
我不喜欢我的代码
文本元素
view【】【】【】【】
IO stream【】【】【】
微信小程序wx.writeBLECharacteristicValue汉字转buffer问题
Chain Reading | The latest and most complete digital collection calendar-07.28
Using sqlplus to operate database in shell script
基于 .NET Core MVC 的权限管理系统
常用类 BigDecimal
Database Notes Create Database, Table Backup
最新最全的数字藏品发售日历-07.26
Linux数据库Oracle客户端安装,用于shell脚本用sqlplus连接数据库