-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo_162.cs
33 lines (26 loc) · 830 Bytes
/
No_162.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Security.AccessControl;
namespace LeetCode
{
class No_162
{
public int FindPeakElement(int[] nums)
{
return VerifyPos(nums, 0,nums.Length-1);
}
private int VerifyPos(int[] nums, int i, int e)
{
int m = i + (e - i) / 2;
if (m == 0)
{
if (m == nums.Length - 1 || nums[m] > nums[m + 1])
return 0;
}
else if (m == nums.Length - 1 && nums[m] > nums[m - 1])
return m;
else if (m != nums.Length - 1 && nums[m] > nums[m - 1] && nums[m] > nums[m + 1])
return m;
var left = m != i ? VerifyPos(nums, i, m - 1) : -1;
return left == -1 && m != e ? VerifyPos(nums, m + 1, e) : left;
}
}
}