class Solution {
public boolean isMonotonic(int[] A) {
return isIncreasing(A) || isDecreasing(A);
}
public boolean isIncreasing(int[] A){
for(int i = 0 ; i < A.length - 1; i++){
if(A[i] > A[i+1]) return false;
}
return true;
}
public boolean isDecreasing(int[] A){
for(int i = 0 ; i < A.length - 1; i++){
if(A[i] < A[i+1]) return false;
}
return true;
}
}
896. Monotonic Array
最新推荐文章于 2022-01-31 01:28:45 发布