One line C++ solution


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

  • 0
    A

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


  • 0
    K

    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.