Skip to content

Commit a030a23

Browse files
authored
Merge pull request neetcode-gh#3029 from benmak11/mono
Create 0896-monotonic-array.java
2 parents e1758b2 + e7578d0 commit a030a23

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

java/0896-monotonic-array.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public boolean isMonotonic(int[] nums) {
3+
boolean inc = true, dec = true;
4+
5+
for (int i = 0; i < nums.length - 1; i++) {
6+
if (nums[i] > nums[i + 1])
7+
inc = false;
8+
if (nums[i] < nums[i + 1])
9+
dec = false;
10+
}
11+
12+
return inc || dec;
13+
}
14+
}

0 commit comments

Comments
 (0)