-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path852.java
More file actions
45 lines (42 loc) · 1.19 KB
/
852.java
File metadata and controls
45 lines (42 loc) · 1.19 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int peakIndexInMountainArray(int[] A) {
int i = 0;
while(i < A.length - 1){
if(A[i] > A[i+1]) {
return i;
}
i++;
}
return i;
}
}
__________________________________________________________________________________________________
sample 38580 kb submission
class Solution {
public int peakIndexInMountainArray(int[] A) {
for (int i = 1; i < A.length - 1; i++) {
if (A[i] > A[i - 1] && A[i] > A[i + 1]) {
return i;
}
}
return -1;
}
}
__________________________________________________________________________________________________
sample 38600 kb submission
class Solution {
public int peakIndexInMountainArray(int[] A) {
int maxVal = A[0],maxIn = 0;
for(int i=1;i<A.length;i++){
if(A[i]> maxVal){
maxVal = A[i];
maxIn = i;
}
else
break;
}
return maxIn;
}
}