class Solution {
public:
int findPeakElement(vector<int>& nums) {
    int i=0;
    int n=nums.size();
    while(i<n){
    if(i==0){   //处理第一位
       if(nums[1] < nums[0])
       return 0;
       else {
        i++;
        continue;
       }
    }
           if(i==n-1){  //处理最后一位
      if(nums[i-1] < nums[i])
      return i;
      else{
      i++;
      continue;
         }
    }
    if((nums[i-1]<nums[i])&&(nums[i]>nums[i+1]))
      return i;
    i++;
    }
return 0;           //处理只有一个元素的情况。。。注意。。。
  }
};

peak num的更多相关文章

  1. LeetCode 162 Find Peak Element

    Problem: A peak element is an element that is greater than its neighbors. Given an input array where ...

  2. Find Peak Element

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

  3. 【leetcode】Find Peak Element

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

  4. find the peak value

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

  5. 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] ≠ ...

  6. LeetCode Find Peak Element

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

  7. 162. Find Peak Element

    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 --------- java

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

  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. 11月09日《奥威Power-BI vs微软Power BI》腾讯课堂开课啦

    上过奥威公开课的同学可能有一个疑问:奥威Power-BI和微软Power BI是同一个吗,为什么叫同样的名字?正如这个世界上有很多个John.Jack.Marry…一样,奥威Power-BI和微软Po ...

  2. SQL Server 2008 R2 数据库安装

    操作系统    Windows server 2008 R2 数据库      SQL Server 2008 R2 注意:SQL Server 2008 R2需要操作系统首先安装.NET Frame ...

  3. 强制回收和IDisposable.Dispose方法

    如果某对象的 Dispose 方法被调用一次以上,则该对象必须忽略第一次调用后的所有调用. 如果对象的 Dispose 方法被多次调用,该对象一定不要引发异常. 除Dispose 之外的实例方法在资源 ...

  4. C++Primer 第五章

    //1.表达式语句的作用:执行表达式并丢弃求值结果 ; value + ; //执行,并丢弃结果 //2.复合语句是指用花括号括起来的语句和声明的序列,复合语句称为块.一个块就是一个作用域.块不以分号 ...

  5. lvs负载均衡的搭建

       lvs负载均衡的搭建 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.         在部署环境前,我们需要了解一下一些协议 一.什么是arp 地址解析协议,即ARP(Addr ...

  6. <s:iterator> 对list操作的一种方法

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA6IAAAH3CAIAAAAuRnW9AAAgAElEQVR4nOzdf4gk1333+wLDDffhPp

  7. [原创]spring学习笔记:关于springsource-tool-suite插件的安装

    1.首先我们得确定自己使用的eclipes的版本,具体方式:打开eclipes > help > About Eclipes > 点击eclipes的logo > 查看ecli ...

  8. C++之路起航——标准模板库(set)

    set(集合):http://baike.baidu.com/link?url=cb68AB-3qfEK8RoaGHJFClb4ZiWpJfc32lPOLtaNUrdxntFC738zCZsCiUlf ...

  9. ef 5 在 DropCreateDatabaseAlways 报错,the connection is currently used

    go sp_who2 -- db_id 数据库名称,查询出来的结果执行一遍就能关闭所有连接 SELECT N'kill '+ CAST(spid AS varchar) FROM master..sy ...

  10. kafka 0.8.x producer Example(scala)

    Producer 最简配置 metadata.broker.list参数指定broker地址,这里不需要填上所有的broker地址,但是如果只写一个,这个broker挂掉后就无法往topic中写入信息 ...