Skip to content

Commit 4063aec

Browse files
committed
added task #941 solution
1 parent 7dcefd6 commit 4063aec

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/task_941/Solution.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package task_941;
2+
3+
public class Solution {
4+
5+
public boolean validMountainArray(int[] arr) {
6+
if (arr.length < 3) {
7+
return false;
8+
}
9+
int top = Integer.MAX_VALUE;
10+
for (int i = 0; i < arr.length - 1; i++) {
11+
if (arr[i] == arr[i + 1]) {
12+
return false;
13+
} else if (arr[i] > arr[i + 1]){
14+
top = i;
15+
if (top == 0) {
16+
return false;
17+
}
18+
break;
19+
}
20+
}
21+
if (!(top >= arr.length || top < 0)) {
22+
for (int i = top + 1; i < arr.length; i++) {
23+
if (arr[i] == arr[i - 1]) {
24+
return false;
25+
} else if (arr[i] > arr[i - 1]) {
26+
return false;
27+
}
28+
}
29+
return true;
30+
} else {
31+
return false;
32+
}
33+
}
34+
35+
}

0 commit comments

Comments
 (0)