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. javac的泛型

    ?:在实例化对象的时候,不确定泛型参数的具体类型时,可以使用通配符进行对象定义. (1)?表示通配符,通配符 与 T 的区别 T:作用于模板上,用于将数据类型进行参数化,不能用于实例化对象. publ ...

  2. Elasticsearch入门(一)

    索引(index) -- 存储关联数据的地方.实际上,索引只是一个逻辑命名空间(logical namespace),它指向一个或多个分片(shards). 分片(shard) 是 工作单元(work ...

  3. C++字符串string类常用操作详解(一)【初始化、遍历、连接】

    代码示例: #include <iostream> #include "string" using namespace std; //字符串初始化 void strIn ...

  4. Ethereum 源码分析之框架

    accounts 实现了一个高等级的以太坊账户管理     bmt          二进制的默克尔树的实现     build           主要是编译和构建的一些脚本和配置     cmd  ...

  5. cgroups简单使用

    Cgroups控制系统资源的分配(cpu.mem.io) 1.cgroups概述 CGroup是Linux内核提供的可以限制.隔离进程组 (process groups) 所使用的物理资源 (如 cp ...

  6. Java指定保留小数位数的方法

    package com.qiyuan.util; import java.math.BigDecimal; import java.math.RoundingMode; import java.tex ...

  7. Linux下C语言的调试--转

    调试是每个程序员都会面临的问题. 如何提高程序员的调试效率, 更好更快地定位程序中的问题从而加快程序开发的进度, 是大家共同面对的问题. 可能Windows用户顺口就会说出:用VC呗 :-) , 它提 ...

  8. 把AspDotNetCoreMvc程序运行在Docker上-part5:使用docker-compose

    在上一part<把AspDotNetCoreMvc程序运行在Docker上-part4:实现负载均衡>中,我们通过几个比较复杂的步骤在docker平台上实现了对网站程序的负载均衡,配置步骤 ...

  9. Golang panic用法

    Go语言追求简洁优雅,所以,Go语言不支持传统的 try…catch…finally 这种异常,因为Go语言的设计者们认为,将异常与控制结构混在一起会很容易使得代码变得混乱.因为开发者很容易滥用异常, ...

  10. vue-router参数传递

    1.在vue-router中,有两大对象被挂载到了实例this2.$route(只读.具备信息的对象).$router(具备函数功能)3.查询字符串方式传递参数 1).去哪里 <router-l ...