Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11f7b03

Browse files
Merge pull requestneetcode-gh#316 from SharmaTushar1/patch-13
Create 852. Peak Index in a Mountain Array.java
2 parentsce96156 +39d9564 commit11f7b03

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//Use binary search
2+
classSolution {
3+
publicintpeakIndexInMountainArray(int[]arr) {
4+
intstart =0;
5+
intend =arr.length;
6+
intn =arr.length;
7+
while (start<=end) {
8+
intmid =start+(end-start)/2;
9+
if (mid!=0 &&mid!=n-1 &&arr[mid-1]<arr[mid] &&arr[mid+1]<arr[mid])
10+
returnmid;
11+
elseif (mid!=n-1 &&arr[mid+1]>arr[mid])
12+
start =mid+1;
13+
elseif (mid!=0 &&arr[mid-1]>arr[mid])
14+
end =mid-1;
15+
}
16+
returnend;
17+
}
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp