We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 51c6b7a commit ba38668Copy full SHA for ba38668
C++/leetcode978_longest_turbulent_subarray/maxturbulencesize.cpp
@@ -0,0 +1,19 @@
1
+class Solution {
2
+public:
3
+ int maxTurbulenceSize(vector<int>& A) {
4
+ int res = 0, clen = 0;
5
+
6
+ for (int i = 0; i < A.size(); i++) {
7
+ if (i >= 2 &&
8
+ ((A[i - 2] > A[i - 1] && A[i - 1] < A[i]) || (A[i - 2] < A[i -1] && A[i - 1] > A[i]))) {
9
+ clen++;
10
+ } else if (i >= 1 && A[i - 1] != A[i]) {
11
+ clen = 2;
12
+ } else {
13
+ clen = 1;
14
+ }
15
+ res = max(res, clen);
16
17
+ return res;
18
19
+};
0 commit comments