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 b8267e5

Browse files
committed
Add solution 162.
1 parent 41b1b6a commit b8267e5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $nums
5+
* @return Integer
6+
*/
7+
function findPeakElement($nums) {
8+
if($nums==null||count($nums)<=1)return 0;
9+
10+
if(count($nums)>=2){
11+
if($nums[count($nums)-1]>$nums[count($nums)-2])return count($nums)-1;
12+
}
13+
14+
for($i=1;$i<count($nums)-1;$i++){
15+
if($nums[$i]>$nums[$i-1]&&$nums[$i]>$nums[$i+1])return $i;
16+
}
17+
18+
return 0;
19+
}
20+
}

0 commit comments

Comments
(0)

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