【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 ...
随机推荐
- linux学习5 Linux开篇入门和基本操作
一.完整的操作系统 1.GNU系统:表示GNU is Not Unix.表示不做商业化.制定了GPL(General Public License)即任何软件程序只要遵循GPL协议就是自由软件.还制定 ...
- mysql 5.7 增删改查及别名的用法
1.启动和停止服务 一)启动和停止 #启动服务: $sudo service mysql start #停止服务: $sudo service mysql stop 二)创建和选择数据库 [创建数据库 ...
- 再做一遍floyed
#include<bits/stdc++.h> #define R register int using namespace std; const int inf=0x3f3f3f3f; ...
- OpenCV Facial Landmark Detection 人脸关键点检测
Opencv-Facial-Landmark-Detection 利用OpenCV中的LBF算法进行人脸关键点检测(Facial Landmark Detection) Note: OpenCV3.4 ...
- Spring|IOC启动流程
1.IOC启动流程 IOC的启动流程分为两个阶段,第一阶段是容器的启动阶段,第二阶段是Bean实例化阶段. 容器的启动阶段:加载配置信息,分析配置信息,其他 Bean实例化阶段:实例化对象,装配依赖, ...
- 利用iterm2,在命令行预览图片,服务器也是可以的
1.首先你本地电脑上要安装iterm2软件,我们这里使用brew安装 这个是一定要装的,因为能在命令行渲染出图片文件全靠它,其实不是服务器渲染出来的,而是iterm2 官方网站:https://www ...
- fmex挂单挖矿
最近fmex上线挂单挖矿,针对挂单写了个程序,"跟随盘口,避免成交",0成本薅羊毛. 代码在 https://github.com/xiaoxiaoleo/fmexminer 使用 ...
- [Windows] 输入字符间距变宽
今天在输入时,不会到误触到哪里,输入的字符间距变得很宽,如下图: 最后找到原因是不小心同时按下了 Shift+Space(空格),进入全角模式,就会导致输入的字符间距变宽 想要恢复,再按一次 shif ...
- 深度学习面试题17:VGGNet(1000类图像分类)
目录 VGGNet网络结构 论文中还讨论了其他结构 参考资料 2014年,牛津大学计算机视觉组(Visual Geometry Group)和Google DeepMind公司的研究员一起研发出了新的 ...
- Vue实现图片预加载
<script>export default { data () { return { count: 0, } }, mounted: function() { this.preload( ...