Created
February 23, 2020 22:17
-
-
Save wushbin/c2af18e6906bb54c815ec3f2feed78bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int findPeakElement(int[] nums) { | |
| int l = 0; | |
| int r = nums.length - 1; | |
| while(l < r) { | |
| int mid = l + (r - l) / 2; | |
| int next = mid + 1; // safe to use mid + 1 | |
| if (nums[mid] < nums[next]) { | |
| l = mid + 1; | |
| } else { | |
| r = mid; | |
| } | |
| } | |
| return l; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment