Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4db46da

Browse files
Update 978.Longest-Turbulent-Subarray.cpp
1 parent 837f69e commit 4db46da

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

‎Others/978.Longest-Turbulent-Subarray/978.Longest-Turbulent-Subarray.cpp‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ class Solution {
1111
else if (A[i]<A[i+1])
1212
q[i] = 1;
1313
}
14-
15-
if (A.size()==1) return 1;
16-
if (A.size()==2) return q[0]==0? 1: 2;
17-
18-
int count = 1;
19-
int start = 0;
20-
for (int i=0; i+1<A.size()-1; i++)
14+
15+
int count = 1;
16+
int i = 0;
17+
while (i<q.size())
2118
{
22-
if (q[i]!=0)
23-
count = max(count, 2);
24-
25-
start = i;
26-
while (i+1<A.size()-1 && q[i]*q[i+1]==-1)
19+
if (q[i]==0)
2720
{
2821
i++;
29-
count = max(count, i-start+2);
22+
continue;
3023
}
24+
25+
int start = i;
26+
while (i+1<q.size() && q[i]*q[i+1]==-1)
27+
i++;
28+
29+
count = max(count, i-start+1+1);
30+
i++;
3131
}
3232

3333
return count;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /