【Leetcode_easy】852. Peak Index in a Mountain Array
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的更多相关文章
- 【LeetCode】852. Peak Index in a Mountain Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 查找最大值位置 寻找第一个下降的位置 日期 ...
- LeetCode 852. Peak Index in a Mountain Array C++ 解题报告
852. Peak Index in a Mountain Array -- Easy 方法一:二分查找 int peakIndexInMountainArray(vector<int>& ...
- LeetCode 852. Peak Index in a Mountain Array (山脉数组的峰顶索引)
题目标签:Binary Search 题目给了我们一组 int array,让我们找到数组的 peak. 利用 binary search, 如果数字比它后面那个数字小,说明还在上坡,缩小范围到右半边 ...
- 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 ...
- 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 = ...
- 852. Peak Index in a Mountain Array
class Solution { public: int peakIndexInMountainArray(vector<int>& A) { return max_element ...
- 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 ...
- Leetcode之二分法专题-852. 山脉数组的峰顶索引(Peak Index in a Mountain Array)
Leetcode之二分法专题-852. 山脉数组的峰顶索引(Peak Index in a Mountain Array) 我们把符合下列属性的数组 A 称作山脉: A.length >= 3 ...
- LeetCode算法题-Peak Index in a Mountain Array(Java实现)
这是悦乐书的第329次更新,第352篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第199题(顺位题号是852).如果以下属性成立,我们将数组A称为山: A.length ...
随机推荐
- Session的应用——三天免登录
1.使用Cookie实现的登录的不足: protected void doGet(HttpServletRequest request, HttpServletResponse response) t ...
- my.conf
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock basedir ...
- Ubuntu 下面手动安装 Redis
1.下载 wget http://download.redis.io/releases/redis-2.8.17.tar.gz .tar.gz cd redis- make 2.复制文件到bin目录 ...
- service 与 log日志
service 初始化执行环境变量PATH和TERM PATH=/sbin:/usr/sbin:/bin:/usr/bin TERM,为显示外设的值,一般为xterm 执行/etc/init.d/目录 ...
- 【概率论】6-3:中心极限定理(The Central Limit Theorem)
title: [概率论]6-3:中心极限定理(The Central Limit Theorem) categories: - Mathematic - Probability keywords: - ...
- Hadoop 副本放置策略的源码阅读和设置
本文通过MetaWeblog自动发布,原文及更新链接:https://extendswind.top/posts/technical/hadoop_block_placement_policy 大多数 ...
- 浅析python迭代器及生成器函数
1. 什么是迭代协议? 迭代协议主要包括两方面的协议集,一种是迭代器协议,另一种是可迭代协议.对于迭代器协议来说,其要求迭代器对象在能够在迭代环境中一次产生一个结果.对于可迭代协议来说,就是一个对象序 ...
- jquery 如何在js中间加入css?
) { $() + 'rem' }) } ) { $( + '%' }) }
- Linux 文件查询
查看文件类型:file 如果你想要知道某个文件的基本数据,例如是属于ASCII或者是data文件,或者是binary,且其中有没有使用到动态函数库等等的信息,可以用file查看 which (寻找“执 ...
- JVM 类加载器的双亲委托机制
1.类加载器的层次结构 在双亲委托机制中,各个加载器按照父子关系形成了树形结构(逻辑意义),除了根加载器之外,其余的类加载器都有且只有一个父加载器. public class MyTest13 { p ...