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

Commit 83c9898

Browse files
162. Find Peak Element
1 parent 78400f3 commit 83c9898

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎162.FindPeakElement.kt‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//https://leetcode.com/problems/find-peak-element/description
2+
class Solution {
3+
fun findPeakElement(nums: IntArray): Int {
4+
var low = 0
5+
var high = nums.size -1
6+
while(low < high){
7+
var mid = low +(high -low)/2
8+
if(nums[mid] > nums[mid+1]){
9+
high = mid
10+
} else {
11+
low = mid + 1
12+
}
13+
}
14+
return low
15+
}
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /