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. leetcode 980. Unique Paths III

    On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  There is e ...

  2. 简单了解node stream

    Almost all Node.js applications, no matter how simple, use streams in some manner. 开篇先吓吓自己.画画图,分析分析代 ...

  3. js 元素offset,client , scroll 三大系列总结

    1,element.offsetWidth : 包括 padding 和 边框 2,element.clientWidth : 包括 padding ,不包含边框 , 内容超出会溢出盒子的时候,就用s ...

  4. java并发编程:线程同步和锁

    一.锁的原理 java中每个对象都有一个内置锁.当程序运行到非静态的synchronized同步方法上时,自动获得与正在执行代码类的当前实例(this)有关的锁.获得一个对象的锁也称为获取锁,当程序运 ...

  5. docker inspect命令查看镜像详细信息

    使用 inspect 命令查看镜像详细信息,包括制作者.适应架构.各层的数字摘要等. # docker inspect --help Usage: docker inspect [OPTIONS] N ...

  6. [转载]MII/MDIO接口详解

    原文地址:MII/MDIO接口详解作者:心田麦浪 本文主要分析MII/RMII/SMII,以及GMII/RGMII/SGMII接口的信号定义,及相关知识,同时本文也对RJ-45接口进行了总结,分析了在 ...

  7. zabbix 图形注释乱码

    1.寻找字体文件 1.1 首先需要找到zabbix后台的字体文件路径,字体文件的后缀为.ttf [root@zabbix ~]# cd /usr/share/zabbix/ [root@zabbix ...

  8. 我来说说XML文件中的xmlns、xmlns:xsi和xsi:schemaLocation、dtd文件的具体含义

    文章摘自:https://yq.aliyun.com/articles/40353               http://www.cnblogs.com/zhao1949/p/5652167.ht ...

  9. VM10 不能安装VMware tools的解决方法

    当安装VMware tools,提示"正在进行简易安装时,无法手动启动VMware TOOLS安装",把CD-ROM设置成自动检测就可以了.

  10. 大数据之Linux

    1 Linux的入门 1.1 概述 Linux内核最初只是由芬兰人林纳斯·托瓦兹(Linus Torvalds)在赫尔辛基大学上出于个人爱好而编写的. Linux是一套免费使用和自由传播的类Unix操 ...