From b1239b4ce882ae135272f62ea3ab387b413c4f44 Mon Sep 17 00:00:00 2001 From: Sk Arman Hossain Date: Fri, 29 Sep 2023 16:22:12 +0000 Subject: [PATCH] Sync LeetCode submission - Monotonic Array (cpp) --- AC-Submissions/problems/monotonic_array/solution.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AC-Submissions/problems/monotonic_array/solution.cpp diff --git a/AC-Submissions/problems/monotonic_array/solution.cpp b/AC-Submissions/problems/monotonic_array/solution.cpp new file mode 100644 index 0000000..c16ebd0 --- /dev/null +++ b/AC-Submissions/problems/monotonic_array/solution.cpp @@ -0,0 +1,12 @@ +class Solution { +public: + bool isMonotonic(vector& nums) { + int direction = 0; + for(int i = 1; i < nums.size(); i++){ + if(direction > 0 && nums[i] < nums[i-1]) return false; + if(direction < 0 && nums[i] > nums[i-1]) return false; + if(direction == 0) direction = nums[i] - nums[i-1]; + } + return true; + } +}; \ No newline at end of file