commit 0e9cc7a3a0215e45e727bf560d4149f4cea05ed9
parent 3c0dee9bfde2225d81c86415f8c5f9b1bf34ee7e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 7 Feb 2023 17:58:34 +0100
Dynamic Programming I: Day 18
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/Problems/0376.cpp b/Problems/0376.cpp
@@ -0,0 +1,14 @@
+class Solution {
+public:
+ int wiggleMaxLength(vector<int> &nums) {
+ if (nums.size() == 0) return 0;
+ int up = 1, down = 1;
+ for (int i = 1; i < nums.size(); i++) {
+ if (nums[i] < nums[i - 1])
+ down = up + 1;
+ else if (nums[i] > nums[i - 1])
+ up = down + 1;
+ }
+ return max(up, down);
+ }
+};
diff --git a/README.md b/README.md
@@ -183,6 +183,7 @@ for solving problems.
| 0350 | Easy | [Intersection of Two Arrays II](Problems/0350.cpp) |
| 0352 | Hard | [Data Stream as Disjoint Intervals](Problems/0352.cpp) |
| 0374 | Easy | [Guess Number Higher or Lower](Problems/0374.cpp) |
+| 0376 | Medium | [Wiggle Subsequence](Problems/0376.cpp) |
| 0383 | Easy | [Ransom Note](Problems/0383.cpp) |
| 0387 | Easy | [First Unique Character in a String](Problems/0387.cpp) |
| 0392 | Easy | [Is Subsequence](Problems/0392.cpp) |