Monotonic Array
看一个队列是不是单调队列, 就是递增or递减.
class Solution {
public boolean isMonotonic(int[] A) {
if(A == null)
return true;
if(A.length == 1)
return true;
boolean res = true;
for(int i = 1; i < A.length; i++) {
if(A[i] < A[i-1])
res = false;
}
if(res)
return res;
res = true; // set to true again.
for(int i = 1; i < A.length; i++) {
if(A[i] > A[i-1])
res = false;
}
return res;
}
}