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. ZooKeeper常见问题(转)

    这段时间来,也在和公司里的一些同学交流使用zk的心得,整理了一些常见的zookeeper问题.这个页面的目标是解答一些zk常见的使用问题,同时也让大家明确zk不能干什么.页面会一直更新. 客户端 1. ...

  2. 前端学习——css基础知识,选择器与html模板、值得收藏的html标签

    一.css需要的html(采用html5标准) DTD,文档类型声明: <!Doctype html> 文本编码声明: <meta charset="utf-8" ...

  3. 为Virtual Studio Code配置Python调试插件(Ubuntu14.04)

    详情见以下python for virtual studio code插件的链接: python 安装依赖 1.Python is installed on the current system Pa ...

  4. Java数据库操作大全

    1.提取单条记录 //import java.sql.*; Connection con=null; Statement stmt=null; ResultSet %%6=null; try { Cl ...

  5. PostgreSQL Loadbalance Analysis CPU

    Before we can even begin to decide on a processor count, we need a baseline. With a working PostgreS ...

  6. Leetcode: Longest Absolute File Path

    Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...

  7. 20145207 《Java程序设计》第8周学习总结

    前言: 这两天电路焊小车,有意思归有意思,确实挺忙的.博客到现在才写.执勤看的东西忘得好快呀,莫名的记不住.不说废话了,开始. 教材学习内容总结: 一.NIO和NIO2 1.NIO的定义 InputS ...

  8. Java基础(31):String的大小写转换、分离成数组、==与equals()的区别(String类)

    继续来看 String 类常用的方法,如下代码所示: 运行结果: 那么,“==” 和 equals() 有什么区别呢? ==: 判断两个字符串在内存中首地址是否相同,即判断是否是同一个字符串对象 eq ...

  9. C++之路进阶——codevs2404(糖果)

    2404 糖果 2011年省队选拔赛四川  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master     题目描述 Description 幼儿园里有N个小朋友,l ...

  10. 【皇甫】☀亲爱的~help me

     亲爱的,我不知道该怎么把我想对你说的话表达出来,希望我对你的认识真的像下面的内容一样,如果我有错,那说明我还不够了解你... 希望我们能够一起走到最后吧... 首先,说说最近的吧,  在我还没有和你 ...