-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_941_valid_mountain_array.java
More file actions
38 lines (34 loc) · 934 Bytes
/
Copy path_941_valid_mountain_array.java
File metadata and controls
38 lines (34 loc) · 934 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
29
30
31
32
33
34
35
36
37
38
public class _941_valid_mountain_array {
public static boolean validMountainArray(int[] a) {
boolean isIncrease = true;
boolean isChanged = false;
int n = a.length;
if (n < 3) {
return false;
}
if (a[0] > a[1]) {
return false;
}
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[i+1]) {
return false;
}
if (a[i] < a[i+1] != isIncrease) {
if ( isChanged == false) {
isChanged = true;
isIncrease = false;
} else {
return false;
}
}
}
if (isChanged == false) {
return false;
}
return true;
}
public static void main(String[] args) {
int[] a = {3,5,5};
System.out.println(validMountainArray(a));
}
}