> For the complete documentation index, see [llms.txt](https://hao-fu-1.gitbook.io/oj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hao-fu-1.gitbook.io/oj/binarysearch/162.-find-peak-element.md).

# 162. Find Peak Element

**分界点很多找其中任意一个的情况**。例如findPeak, 它的peak(波)可以有很多，peak(波)之间也没有性质能把它们区分出来，乍看上去不适用于二分。但题目要求并不是找特定的peak，而是找到任意一个就行了。因此给定的数列可以划分成俩坨，前面那坨满足严格上升（题有说前后俩元素不会相等），后面那坨满足严格下降，返回的也就是个划分点peak。只是我们无法用这个方法找到特定的peak。

由于要返回的是peak, 如果在判断上升后把start移到mid后可能会错过这最后的peak。因此判断不是上升把end移动到mid前是最合理的。还有当mid == start时，如\[2, 3]，因为现在不会让start移到mid后，需要强制退出。

```
/*
 * @lc app=leetcode id=162 lang=cpp
 *
 * [162] Find Peak Element
 */
class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        if (nums.size() == 1) return 0;
        int start = 1, end = nums.size() - 1;
        while (start < end) {
            int mid = start + (end - start) / 2;
            if (start == mid) {
                start = nums[end] > nums[start] ? end : start;
                break;
            }
            if (!(nums[mid] > nums[mid - 1])) end = mid - 1;
            else start = mid;
        }
        return start == 1 && nums[0] > nums[start] ? 0 : start;
    }
};


```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hao-fu-1.gitbook.io/oj/binarysearch/162.-find-peak-element.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
