/** * @param {number[]}A * @return {number} */ var longestMountain = function (A) { let max = 0; let status = 0; let pre = null; let length = 0; for (let i = 0; i < A.length; i++) { if (status === 0) { if (!length || A[i] > pre) { pre = A[i]; length++; } elseif (length >= 2 && A[i] < pre) { pre = A[i]; length++; status = 1; if (i === A.length - 1) max = Math.max(length, max); } else { pre = A[i]; length = 1; } } else { if (A[i] < pre) { pre = A[i]; length++; if (i === A.length - 1) max = Math.max(length, max); } else { max = Math.max(length, max); status = 0; pre = A[--i]; length = 1; } } }