My 8ms C++ Solution


  • 1
    G
    class Solution {
    public:
        int findPeakElement(vector<int>& nums) {
            int len=nums.size(),l=0,r=len-1;
            while (l<=r) {
                int mid=(l+r)>>1;
                if (mid<len-1 && nums[mid+1]>nums[mid])
                    l=mid+1;
                else
                    if (mid>0 && nums[mid-1]>nums[mid])
                        r=mid-1;
                    else
                        return mid;
            }
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.