Skip to content

Commit

Permalink
Sync LeetCode submission - Monotonic Array (cpp)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheikh-arman committed Sep 29, 2023
1 parent b52d7af commit b1239b4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AC-Submissions/problems/monotonic_array/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public:
bool isMonotonic(vector<int>& 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;
}
};

0 comments on commit b1239b4

Please sign in to comment.