commit 9dc1c23a742de973494051e8859e05a3d24e2bc2
parent 3faa33aef172e429db053f3151951507106163d4
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Fri, 29 Sep 2023 14:10:02 +0000
Daily Problem
Diffstat:
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Problems/0896.cpp b/Problems/0896.cpp
@@ -0,0 +1,12 @@
+class Solution {
+ public:
+ bool isMonotonic(const vector<int> &nums) {
+ bool inc = false, dec = false;
+ for (int i = 1; i < nums.size(); i++) {
+ if (nums[i] > nums[i - 1]) dec = true;
+ if (nums[i] < nums[i - 1]) inc = true;
+ if (dec && inc) break;
+ }
+ return !(dec & inc);
+ }
+};
diff --git a/README.md b/README.md
@@ -440,6 +440,7 @@ for solving problems.
| 0890 | Medium | [Find and Replace Pattern](Problems/0890.cpp) |
| 0893 | Medium | [Groups of Special-Equivalent Strings](Problems/0893.cpp) |
| 0894 | Medium | [All Possible Full Binary Trees](Problems/0894.cpp) |
+| 0896 | Easy | [Monotonic Array](Problems/0896.cpp) |
| 0897 | Easy | [Increasing Order Search Tree](Problems/0897.cpp) |
| 0901 | Medium | [Online Stock Span](Problems/0901.cpp) |
| 0904 | Medium | [Fruit Into Baskets](Problems/0904.cpp) |