Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-12-10_00-33-55.png
37.7 KB
#N896. Monotonic Array
problem link

#solution
class Solution {
public boolean isMonotonic(int[] nums) {
int countI=0, countD=0, l=nums.length;
for(int i=0; i<l-1; i++){
if(nums[i] == nums[i+1]){
countI++;
countD++;
}
else if(nums[i] < nums[i+1]) countI++;
else countD++;
}

return countI == l-1 || countD == l-1;
}
}