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. 【数组】Majority Element II

    题目: Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The alg ...

  2. Android之从TCP/IP、HTTP看Socket通信

    1.概念 TCP/IP:属于传输层/网络层协议.手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络数据的传 ...

  3. Android硬件抽象层(HAL)深入剖析(三)【转】

    前面分析了android HAL层是如何搜索硬件模块的动态共享库的,其实就是在"system/lib/hw/"或者"/vendor/lib/hw/"这两个路径下 ...

  4. Django如何让未登录的用户自动跳转至登录页

    有多种方法可以实现: 使用Django自带的用户认证 from django.contrib.auth.decorators import login_required @login_required ...

  5. System.Windows.Forms.Timer的简单用法

    Timer就是用来计时操作,如:你想在多少秒之后执行某个动作 Timer showTextBoxTimer = new Timer(); //新建一个Timer对象 showTextBoxTimer. ...

  6. 在没有jre环境下运行jar

    1.首先将程序打包(这一步可以通过eclipse的导出完成). 2.为项目添加第三方jar包.在第1步打好的jar包的同级目录下,新建一个lib(名字可以自取)文件夹.用winrar等解压文件打开第1 ...

  7. 微服务 + Docker + Kubernetes 入门实践 目录

    微服务 + Docker + Kubernetes 入门实践: 微服务概念 微服务的一些基本概念 环境准备 Ubuntu & Docker 本文主要讲解在 Ubuntu 上安装和配置 Dock ...

  8. 【WePY小程序框架实战二】-页面结构

    [WePY小程序框架实战一]-创建项目 项目结构 |-- dist |-- node_modules |-- src | |-- components |-- a.wpy |-- b.wpy |-- ...

  9. PHP 集成开发环境比较

    专注了这么些年技术,没有养成记录和积累的习惯.如今乐于开源和分享经验,却停笔踌躇,不知该从何处说起.开通博客也有一段时间了,也没能写出一篇像样的文章,其实这篇文章也是被我拉壮丁似的用来练手的.思前想后 ...

  10. [整理]EF6.X更新了什么(版本历史中文版)

    下定决心以后用EF6.x版本了.想看看有什么更新特性,结果去人家github老巢一看,EF7 for vnext,顿时蛋疼了起来.想想国内这种技术氛围,有多少还在用ASP的,有多少还在用ADO.NET ...