Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] Given an array that is definitely…
852. Peak Index in a Mountain Array -- Easy 方法一:二分查找 int peakIndexInMountainArray(vector<int>& A) { // insert another two elements to avoid out of bound const int INT_MAX_ = 2147483647; const int INT_MIN_ = (-INT_MAX_-1); // insert INT_MIN_ befo…
题目要求 Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] Given an array that is defin…
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 peakIndexInMountainArra…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 查找最大值位置 寻找第一个下降的位置 日期 题目地址:https://leetcode.com/problems/peak-index-in-a-mountain-array/description/ 题目描述 Let's call an array A a mountain if the following properties hold…