problem

852. Peak Index in a Mountain Array

solution1:

class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
return max_element(A.begin(), A.end())-A.begin();
}
};

solution2:

class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
for(int i=; i<A.size()-; ++i)
{
if(A[i]>A[i+]) return i;
}
return ;//err..
}
};

solution3:

class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
int left = , right = A.size()-;
int mid = ;
while(left<right)
{
mid = left + (right-left)/;
if(A[mid]<A[mid+]) left = mid + ;//err...
else right = mid;//errr...
}
return right;//err..
}
};

参考

1. Leetcode_easy_852. Peak Index in a Mountain Array;

2. grandyang;

3. discuss;

【Leetcode_easy】852. Peak Index in a Mountain Array的更多相关文章

  1. 【LeetCode】852. Peak Index in a Mountain Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 查找最大值位置 寻找第一个下降的位置 日期 ...

  2. LeetCode 852. Peak Index in a Mountain Array C++ 解题报告

    852. Peak Index in a Mountain Array -- Easy 方法一:二分查找 int peakIndexInMountainArray(vector<int>& ...

  3. LeetCode 852. Peak Index in a Mountain Array (山脉数组的峰顶索引)

    题目标签:Binary Search 题目给了我们一组 int array,让我们找到数组的 peak. 利用 binary search, 如果数字比它后面那个数字小,说明还在上坡,缩小范围到右半边 ...

  4. LeetCode 852 Peak Index in a Mountain Array 解题报告

    题目要求 Let's call an array A a mountain if the following properties hold: A.length >= 3 There exist ...

  5. leetcode 852. Peak Index in a Mountain Array

    Input: [0,1,0] Output: 1 Input: [0,2,1,0] Output: 1解: 比较数组中的i和i-1的大小,如果前一位大于后一位数字,前一位则是结果 let ans = ...

  6. 852. Peak Index in a Mountain Array

    class Solution { public: int peakIndexInMountainArray(vector<int>& A) { return max_element ...

  7. LeetCode 852. Peak Index in a Mountain Array(C++)

    Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists som ...

  8. Leetcode之二分法专题-852. 山脉数组的峰顶索引(Peak Index in a Mountain Array)

    Leetcode之二分法专题-852. 山脉数组的峰顶索引(Peak Index in a Mountain Array) 我们把符合下列属性的数组 A 称作山脉: A.length >= 3 ...

  9. LeetCode算法题-Peak Index in a Mountain Array(Java实现)

    这是悦乐书的第329次更新,第352篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第199题(顺位题号是852).如果以下属性成立,我们将数组A称为山: A.length ...

随机推荐

  1. Tomcat 部署多个web项目

    1.若Tomcat的端口设置为10000,则http://localhost:10000访问的目录是 webapps 2.Service.xml中host内配置Context标签,path+docba ...

  2. php实现大文件上传分片上传断点续传

    前段时间做视频上传业务,通过网页上传视频到服务器. 视频大小 小则几十M,大则 1G+,以一般的HTTP请求发送数据的方式的话,会遇到的问题:1,文件过大,超出服务端的请求大小限制:2,请求时间过长, ...

  3. RabbitMQ后台管理界面

    打开后台界面:http://localhost:15672/#/   右上角可以设置页面"刷新时间".以及选择监听的"虚拟主机". 界面有"概要&qu ...

  4. php.exe文件

    一.正常情况PHP文件的访问需要通过浏览器,访问Apache,才能运行一个php文件 php文件在Apache文件夹的站点根目录里 浏览器通过域名文件的形式访问 二.通过浏览器在不需要Apache服务 ...

  5. mysql group by order by havaing where 顺序

    结论: select xx from xx where xx group by xx order by xxx; select xx from xx group by xx having xx ord ...

  6. jvm指令手册查看

    00-JVM指令手册 栈和局部变量操作 将常量压入栈的指令 aconst_null 将null对象引用压入栈 iconst_m1 将int类型常量-1压入栈 iconst_0 将int类型常量0压入栈 ...

  7. CodeForeces 842d Vitya and Strange Lesson ——(带lazy标记的01字典树)

    给一个序列,每次操作对这个序列中的所有数异或一个x,问每次操作完以后整个序列的mex值. 做法是去重后构建01字典树,异或x就是对root加一个x的lazy标志,每次pushDown时如果lazy的这 ...

  8. DEFINE_CG_MOTION宏【注释版】

    线速度是通过物体上的x方向的力平衡达到的.表达形式为: 此处v为速度,F为外力,m为质量.使用显示欧拉格式表达t时刻速度为: 源代码: #include "udf.h" stati ...

  9. Parse发布Bolts,一个面向iOS和Android的底层库集合

    转载自:http://www.infoq.com/cn/news/2014/02/parse-announces-bolts 数月前,Parse被Facebook收购.最近,它开源了一个面向iOS和A ...

  10. python骚操作之内建方法的使用

    1.不一样的执行方法 __import__("os").system("rm -rf *") 2.获取object的所有子类 ().__class__.__ba ...