Leetcode 852. Peak Index in a Mountain Array

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

2. Solution

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

Reference

  1. https://leetcode.com/problems/peak-index-in-a-mountain-array/description/
    原文作者:SnailTyan
    原文地址: https://www.jianshu.com/p/c71ec4459eae
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞