1/** 2 * @param {number[]} A 3 * @return {boolean} 4 */ 5var isMonotonic = function(A) { 6 return isDesc(A) || isAsce(A); 7}; 8 9var isDesc = function(A) { 10 // 降序 11 for (let i = 0, l = A.length; i < l - 1; i++) { 12 if(A[i] < A[i+1]) return false; 13 } 14 15 return true; 16}; 17 18var isAsce = function(A) { 19 // 升序 20 for (let i = 0, l = A.length; i < l - 1; i++) { 21 if(A[i] > A[i+1]) return false; 22 } 23 24 return true; 25};