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. 用jquery快速解决IE输入框不能输入的问题_jquery

    代码如下: 在IE10以上版本,微软为了提高IE输入框的便利性,增加了文本内容全部删除和密码眼睛功能,但是有些时候打开新的页面里,输入框却被锁定无法编辑,需要刷新一下页面,或者如果输入框有内容需要点击 ...

  2. [CSS] Create a Card Flip Animation with CSS

    Animation can be a powerful way to enhance a user experience. In this lesson, we'll walk through the ...

  3. web 字体 font-family

    body { font-family: -apple-system, //针对 Web 页面 BlinkMacSystemFont, //针对 Mac Chrome 页面 SFProDisplay, ...

  4. Linux Vbox 桥接模式上网配置

    1.Bridged Adapter模式(桥接模式)特点: 1)如果主机可以上网,虚拟机可以上网 2)虚拟机之间可以ping通 3)虚拟机可以ping通主机 4)主机可以ping通虚拟机以上各点基于一个 ...

  5. mysql 8.0.17 安装配置方法图文教程

    1.URL:https://www.jb51.net/article/167782.htm 2.装好之后需要使用add user中的用户名和密码登录(之前安装数据库时出现的) 使用navicat连接时 ...

  6. 【转】根据Quartz-Cron表达式获取最近几次执行时间

    public static List<String> getRecentTriggerTime(String cron) { List<String> list = new A ...

  7. 代码格式化工具---indent工具

    indent工具,可以把代码格式化成某种风格. 通过命令:rpm -qa | grep indent 查看是否安装了indent工具. 若没有,可使用命令sudo apt-get  install   ...

  8. leetcode解题报告(32):Teemo Attacking

    描述 In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poison ...

  9. 【概率论】5-9:多项式分布(The Multinomial Distributions)

    title: [概率论]5-9:多项式分布(The Multinomial Distributions) categories: - Mathematic - Probability keywords ...

  10. Tkinter 之ProgressBar进度条标签

    一.参数说明 参数 作用 cursor 鼠标位于进度条内时的形状 length 进度条长度 maximum 进度条最大刻度值 mode  进度条的模式.有两种:‘determinate’和’indet ...