Skip to content

Commit eedfe01

Browse files
authored
Create Solution.java
1 parent cd8c86d commit eedfe01

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int maxTurbulenceSize(int[] A) {
3+
int res = 1;
4+
int up = 1, down = 1;
5+
for (int i = 1; i < A.length; ++i) {
6+
if (A[i] > A[i - 1]) {
7+
up = down + 1;
8+
down = 1;
9+
res = Math.max(res, up);
10+
} else if (A[i] < A[i - 1]) {
11+
down = up + 1;
12+
up = 1;
13+
res = Math.max(res, down);
14+
} else {
15+
up = 1;
16+
down = 1;
17+
}
18+
}
19+
return res;
20+
}
21+
}

0 commit comments

Comments
 (0)