1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| class Solution { public boolean validMountainArray(int[] A) { int n = A.length; if(n < 3){ return false; } for(int i = 1; i < n-1; i++){ int k1 = i; int k2 = i; while(k1 >= 1 && A[k1] > A[k1-1]){ k1--; }
if(k1 != 0){ continue; }
while(k2 < n-1 && A[k2] > A[k2+1]){ k2++; }
if(k2 == n -1){ return true; } } return false; } }
|