Skip to content

Commit

Permalink
Time: 4 ms (56.21%), Space: 7 MB (95.65%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Pjha72 committed Jul 3, 2022
1 parent 9fc8978 commit dfe16f4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 376-wiggle-subsequence/376-wiggle-subsequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
if(nums.size()<=1){
return nums.size();
}
int upcount=1,downcount=1;
for(int i=0;i<nums.size()-1;i++){
if(nums[i]<nums[i+1]){
upcount=downcount+1;
}
else if(nums[i]>nums[i+1]){
downcount=upcount+1;
}
}
int ans = max(upcount,downcount);
return ans;
}
};

0 comments on commit dfe16f4

Please sign in to comment.