1、题目描述

2、题目分析

在数组的首尾各加入INT_MIN ,然后遍历数组。

3、代码

 int findPeakElement(vector<int>& nums) {
if( nums.size() == )
return ; nums.insert( nums.begin(), INT_MIN );
nums.push_back( INT_MIN ); for( vector<int>::iterator it = nums.begin()+; it != nums.end() - ; ++it ){
if( *it > *(it + ) && *it > *(it-) )
return (it - nums.begin() - );
}
}

LeetCode 题解之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 (3 solutions)

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

  4. LeetCode OJ:Find Peak Element(寻找峰值元素)

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

  5. 【刷题-LeetCode】162 Find Peak Element

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

  6. leetcode 日记 162. Find Peak Element java python

    根据题目可知,输入为:一个相邻元素不相等的数列,输出为:其中一个(上)峰值的序号.并且要求时间复杂度为logn 分析:由于题目要求时间复杂度为logn,因此不能进行全部遍历.又因为只需要找到其中的一个 ...

  7. LeetCode Find Peak Element

    原题链接在这里:https://leetcode.com/problems/find-peak-element/ 题目: A peak element is an element that is gr ...

  8. (二分查找 拓展) 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 ...

  9. [LeetCode] Find Peak Element 求数组的局部峰值

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

随机推荐

  1. python 把一文件包含中文的字符写到另外文件乱码 UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position

    报错的代码是: file2 = open('target.txt','w')for line in open('test.txt'): file2.write(line)原因:文件编码不一致导致解决方 ...

  2. php如何判断字符串是否是字母和数字的组合

    转载自百度 /其实判断是否是字母和数字或字母数字的组合还可以用PHP ctype_alnum函数 if(!ctype_alnum($vipurl)){ echo '只能是字母或数字的组合';exit; ...

  3. 快速搭建gulp项目实战

    gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:她不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成:使用她,我们不仅可以很愉快的编写代码,而且大 ...

  4. 06-python中的装饰器

    java类中, 有一系列的装饰器, 尤其对文件的操作, python的装饰器比较简单, 直接上代码 #!/usr/bin/env python3 #coding:utf- ''' python的装饰器 ...

  5. Linux内存信息查看——free命令

    free 命令可以显示系统已用和空闲的内存情况.包括物理内存.交互区内存(swap)和内核缓冲区内存(buffer).共享内存将被忽略.在Linux系统监控的工具中,free命令是最经常使用的命令之一 ...

  6. HTTPClient 超时链接设置

    远程访问链接,设置时间,从而减少不必要的麻烦,但是HttpClient版本不一致,方法不一样,所以有了如下设置 原帖链接:https://www.cnblogs.com/jimmy-muyuan/p/ ...

  7. 入坑python 自己写的小工具,纪念一下

    这个程序的功能是可以从表格中读取某一列数据,传到IDs 这一个参数里,然后在url中获取相应的请求值,并打印 import urllib.request import json import xlrd ...

  8. C#对json数据的解析

    一,基础知识 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类 ...

  9. Leetcode 762. Prime Number of Set Bits in Binary Representation

    思路:动态规划.注意1024*1024>10^6,所以质素范围是(0,23). class Solution { public int countPrimeSetBits(int L, int ...

  10. JS的作用域和声明提前

    首先介绍下Javascript的函数作用域的概念,然后了解下什么是作用域和声明提前,最后通过一个例子剖析Javascript的作用域链. 1.变量的作用域 稍微有些编程背景的都知道,变量的作用域分为两 ...