One line C++ solution

  • 0
    int findPeakElement(vector<int>& nums) {
        return max_element(nums.begin(), nums.end()) - nums.begin();

  • 0

    This is great and elegant.Could you please elaborate, however, why is this giving a correct solution.

  • 0

    It's just a linear search for the max element, which would be a guaranteed peak.

Log in to reply

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