Skip to content

Commit bc78ae5

Browse files
committed
Add 896-MonotonicArray.cpp
1 parent 6959159 commit bc78ae5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
bool isMonotonic(vector<int>& nums) {
4+
bool up(true), down(true);
5+
for(int p = 1; p < nums.size(); p++){
6+
if(nums[p - 1] < nums[p]){up = false;}
7+
if(nums[p - 1] > nums[p]){down = false;}
8+
}
9+
10+
return up || down;
11+
}
12+
};

0 commit comments

Comments
 (0)