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. [BS-16] 尽量将View的Opaque属性设置为YES(默认就是YES)

    尽量将View的Opaque属性设置为YES(默认就是YES) UIView控件都有一个Opaque属性,如果不会更改view的透明度,那么应该将其opaque属性设置为YES.为什么要这样做呢?其实 ...

  2. ios webView 默认有缓存

    ios webview清除缓存. ios默认webview是有缓存的,所以不改变URL的话,刷新不了网页数据,或者像我这样写 NSMutableURLRequest *request = [NSMut ...

  3. 利用selenium Server实现IE firefox 和 chrome兼容性测试

    本文的主题是基于Selenium Server,使用 Java 语言编写网页交互流程, 实现多浏览器(IE Firefox Chrome)兼容性测试,为使用纪要. Selenium Selenium是 ...

  4. 用get方式提交请求的url带有中文参数

    又碰到JSP页面中文乱码问题,经过一次encodeURI处理后仍旧是乱码,后来经过两次encodeURI后正常显示中文 以前也碰到过同样的问题,没深究,这次网上搜集了一些资料,记录下来留做备份 ___ ...

  5. c# Start/Stop/Check Status远程计算机的Windows Service

    static void Main(string[] args) { ConnectionOptions op = new ConnectionOptions(); // 登陆远程计算机的远程, op. ...

  6. 如何在RedHat6(7) or CentOS6(7)上制作无依赖的PostgreSQL数据库的RPM包

    本文解决了源代码安装都需要先检查系统上是否安装了应用程序所依赖的软件包的烦恼,对源代码开发者也有一定的帮助.可以在该基础上进行适当的修改,以满足自己的要求. RedHat5 or CentOS5已经提 ...

  7. 找区间连续值(HDU5247)

    找连续数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. nyist 676 小明的求助

    http://acm.nyist.net/JudgeOnline/problem.php?pid=676 小明的求助 时间限制:2000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  9. Java基础(51):Super与this的区别

    1.     子类的构造函数如果要引用super的话,必须把super放在函数的首位. class Base { Base() { System.out.println("Base" ...

  10. oracle 复杂语句

    select nvl(sum1,'0')as sum1,nvl(sum2,'0') as sum2,da2 from( select count(*) as sum1,substr(APPLY_DAT ...