-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArray32.java
More file actions
28 lines (24 loc) · 810 Bytes
/
Array32.java
File metadata and controls
28 lines (24 loc) · 810 Bytes
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
package array;
/**
* Project Admin -> Husanboy Azamov
* Package Name -> array
* Class Name -> Array32
* Copyright © : 6/23/2022
*/
public class Array32 {
public static void main(String[] args) {
int[] array = new int[]{3,2,4,5,6,7,8,9,10,5,11,};
System.out.println(solution(array));
}
public static int solution(int[] array) {
for (int i = 1; i < array.length - 1; i++) {
// Local minimum -> a[i-1] > a[i] && a[i] < a[i+1]
// Local maximum -> a[i-1] < a[i] && a[i] > a[i+1]
// boolean isLocalMax = array[i - 1] < array[i] && array[i] > array[i + 1];
boolean isLocalMin = array[i - 1] > array[i] && array[i] < array[i + 1];
if (isLocalMin)
return i;
}
return -1;
}
}