Skip to content

Commit 24b6cb5

Browse files
authored
Create 3105. Longest Strictly Increasing or Strictly Decreasing Subarray (#705)
2 parents 052a8ce + 0e0c942 commit 24b6cb5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int longestMonotonicSubarray(vector<int>& nums) {
4+
int res = 1, low = 1, high = 1;
5+
for (int i = 1; i < nums.size(); i++){
6+
if (nums[i] > nums[i - 1]){
7+
high++;
8+
low = 1;
9+
}
10+
else if (nums[i] < nums[i - 1]){
11+
low++;
12+
high = 1;
13+
}
14+
else{
15+
low = 1;
16+
high = 1;
17+
}
18+
res = max({res, low, high});
19+
}
20+
return res;
21+
}
22+
};

0 commit comments

Comments
 (0)