File tree 1 file changed +12
-1
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,18 @@ public static class Solution1 {
7
7
* credit: https://leetcode.com/problems/find-peak-element/solutions/1290642/intuition-behind-conditions-complete-explanation-diagram-binary-search/
8
8
* Time: O(logn)
9
9
* <p>
10
- * draw three cases with three examples, it's pretty self-explanatory
10
+ * draw three cases with three examples, it's pretty self-explanatory:
11
+ * case 1:
12
+ * mid
13
+ * 1, 3, 2
14
+ * case 2:
15
+ * mid
16
+ * 1, 2, 3
17
+ * so peak should be on the right side, so code is: left = mid + 1
18
+ * case 3:
19
+ * mid
20
+ * 3, 2, 1
21
+ * so peak should be on the left side, so code is: right = mid - 1;
11
22
*/
12
23
public int findPeakElement (int [] nums ) {
13
24
if (nums == null || nums .length <= 1 || nums [0 ] > nums [1 ]) {
You can’t perform that action at this time.
0 commit comments