当前位置:网站首页>LeetCode 162. Finding Peaks (Moderate)
LeetCode 162. Finding Peaks (Moderate)
2022-08-10 05:54:00 【Shengxin Research Ape】
python
class Solution:def findPeakElement(self, nums: List[int]) -> int:if(len(nums)==1):return 0if(nums[0]>nums[1]):return 0if(nums[len(nums)-1]>nums[len(nums)-2]):return len(nums)-1'''Complexity O(n)i = 1while(1):if(nums[i]>nums[i-1] and nums[i]>nums[i+1]):breaki +=1return i'''#dichotomyleft = 0right = len(nums)-1while(leftnums[mid+1]):right = midelse:left = mid +1return left
边栏推荐
猜你喜欢
Analysis of the investment value of domestic digital collections
LeetCode 162.寻找峰值(中等)
数据库 笔记 创建数据库、表 备份
机器学习——聚类——商场客户聚类
Collection tool class
The latest and most complete digital collection sales calendar-07.26
One step ahead, don't miss it again, the chain reading APP will be launched soon!
图片批量添加水印批量加背景缩放批量合并工具picUnionV4.0
树结构——二叉查找树原理与实现
MySQL中MyISAM为什么比InnoDB查询快
随机推荐
MySql constraints
索引笔记【】【】
常用类 String概述
优先队列
最新最全的数字藏品发售日历-07.27
Chain Reading Good Article: Jeff Garzik Launches Web3 Production Company
pytorch-06.逻辑斯蒂回归
Chain Reading|The latest and most complete digital collection sales calendar-07.29
链读|最新最全的数字藏品发售日历-08.02
基于 .NET Core MVC 的权限管理系统
WeChat applet wx.writeBLECharacteristicValue Chinese character to buffer problem
栈和队列
generic notes()()()
ACID四种特性
Collection set interface
Consensus calculation and incentive mechanism
LeetCode 292.Nim 游戏(简单)
ZigBee 网络设备相关内容
卷积神经网络(CNN)实现服装图像分类
集合 Map