Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Leetcode problem number 852

pratik.rajput17

New member
Joined
Sep 27, 2024
Messages
4
Hi, can you send me the solution for this question which is Peak Index in a Mountain Array?
 
C++:
class Solution {
public:
    int peakIndexInMountainArray(vector<int>& v) {

        int s=0;
        int m;
        int e=v.size()-1;

        while(s<=e)
        {
            m=(s+(e-s)/2);

            if(v[m]>v[m+1] && v[m]>v[m-1])
                return m;

            else if(v[m+1]>v[m]) s=m+1;

            else e=m-1;

        }

        return 0;
        
    }
};
 
Back
Top