Skip to content

Commit

Permalink
Create 3105. Longest Strictly Increasing or Strictly Decreasing Subar…
Browse files Browse the repository at this point in the history
…ray (#705)
  • Loading branch information
Chayandas07 authored Feb 3, 2025
2 parents 052a8ce + 0e0c942 commit 24b6cb5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 3105. Longest Strictly Increasing or Strictly Decreasing Subarray
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
int longestMonotonicSubarray(vector<int>& nums) {
int res = 1, low = 1, high = 1;
for (int i = 1; i < nums.size(); i++){
if (nums[i] > nums[i - 1]){
high++;
low = 1;
}
else if (nums[i] < nums[i - 1]){
low++;
high = 1;
}
else{
low = 1;
high = 1;
}
res = max({res, low, high});
}
return res;
}
};

0 comments on commit 24b6cb5

Please sign in to comment.