https://leetcode-cn.com/contest/weekly-contest-100/problems/monotonic-array/

我的解决方案:

package tet;

class Solution
{
public boolean isMonotonic(int[] A)
{
//假设为单调递减
boolean flagDec=true;
for(int i=0; i<A.length-1; i++)
{
if(A[i]<A[i+1])
{
flagDec=false;
break;
}
}
if(flagDec) return flagDec;

//再判断是否为单调递增
boolean flagInc=true;
for(int i=0; i<A.length-1; i++)
{
if(A[i]>A[i+1])
{
flagInc=false;
break;
}
}
if(flagInc)return true;

return false;
}
}