C++ Less 10 line solution, Binary Search


  • 2
    L
     int findPeakElement(vector<int>& nums) {
        const int size_num = nums.size();
        int i = 0, j = size_num - 1;
        while (i < j) {
            int mid = i + (j - i) / 2;
            if (nums[mid] < nums[mid+1]) i = mid + 1;
            else j = mid;
        }
        return i;
    }

Log in to reply
 

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