mycode  54.81%

class Solution(object):
def findPeakElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) == 0:
return None
if len(nums) == 1 or nums[0]>nums[1] :
return 0
if nums[-1] > nums[-2]:
return len(nums)-1 for i in range(1,len(nums)-1):
if nums[i] > nums[i-1] and nums[i] > nums[i+1]:
return i

参考:

思路:题目中左右为负无穷这个条件可以用起来,把原列表扩增以下就可以把两端的情况合并在一个for循环讨论啦

import math
class Solution(object):
def findPeakElement(self, nums):
"""
:type nums: List[int]
:rtype: int
""" nums = [-float('inf')] + nums + [-float('inf')]
for i in range(1, len(nums)-1):
if nums[i-1] < nums[i] > nums[i+1]:
return i-1

leetcode-mid-sorting and searching-162. Find Peak Element的更多相关文章

  1. 【LeetCode】162. Find Peak Element 解题报告(Python)

    [LeetCode]162. Find Peak Element 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/ ...

  2. LeetCode OJ 162. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  3. LeetCode 162. Find Peak Element (找到峰值)

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  4. (二分查找 拓展) leetcode 162. Find Peak Element && lintcode 75. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...

  5. [LeetCode] 162. Find Peak Element 查找峰值元素

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  6. Java for LeetCode 162 Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  7. ✡ leetcode 162. Find Peak Element --------- java

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  8. 【LeetCode】162. Find Peak Element (3 solutions)

    Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...

  9. leetcode 162 Find Peak Element(二分法)

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  10. LeetCode 162.Find Peak Element(M)(P)

    题目: A peak element is an element that is greater than its neighbors. Given an input array where num[ ...

随机推荐

  1. C语言几种常用的排序算法

    /* ============================================================================= 相关知识介绍(所有定义只为帮助读者理解 ...

  2. WLAN AutoConfig服务无法开机自动启动

    又到“618”大促销,商家搞活动,买了一只小无线网卡,刚装上,一切正常.重新启动电脑后,发现无线网卡已被禁用!手工启用无线网卡也不能解决.到“计算机管理”-“服务”中将“WLAN Autoconfig ...

  3. POSTGRESQL 批量权限 管理方法

    原博地址 https://yq.aliyun.com/articles/41512?spm=a2c4e.11153940.0.0.20b7640fcDiFQA 关于PostgreSQL的逻辑架构和权限 ...

  4. centos7 远程桌面连接到xfce桌面

    1 安装xfce $ sudo yum install -y epel-release $ sudo yum groupinstall -y "Xfce" $ sudo reboo ...

  5. windows中ftp下载脚本(bat+vb)

    做了个ftp下载脚本: ftpdownload.bat @rem 注释:从ftp服务器每小时下载北向性能文件的脚本 @rem 用vb脚本取昨天 for /f %%a in ('cscript //no ...

  6. MFC界面库BCGControlBar v30.1新功能详解:Dialogs和Forms

    亲爱的BCGSoft用户,我们非常高兴地宣布BCGControlBar Professional for MFC和BCGSuite for MFC v30.1正式发布!此版本包含themed find ...

  7. Django ckeditor增加编辑代码 功能

    前言 使用ckeditor这个组件的时候 对于长写博客的同学当然希望能有 增加代码这个功能按钮 而这个按钮 需要自己配置 我们的编辑器自然需要添加代码块的功能. 需要用到插件codesnippet,c ...

  8. redux 中的 redux-thunk(中间件)

    前言 空闲时间把redux中的redux-thunk中间件回顾下,因为以前没有写博客的习惯,都怪自己太年轻,好了 其实:      redux的核心概念其实很简单:将需要修改的state都存入到sto ...

  9. HDU-3081-Marriage Match 2(最大流, 二分答案, 并查集)

    链接: https://vjudge.net/problem/HDU-3081 题意: Presumably, you all have known the question of stable ma ...

  10. kafka2.12_1.0.1生产者示范代码

    import java.util.Properties;import kafka.javaapi.producer.Producer;import kafka.producer.KeyedMessag ...