public static boolean isBSTSequence(int[] s,int l, int r) { if (s == null || r <= 0) return false; int n = r; int root = s[n - 1]; int i = 0; for (; i < n - 1; i++) { if (s[i] > root) break; } int j = i; for (; j < n - 1; j++) { if (s[j] < root) return false; } boolean left = true; if (i > 0) left = isBSTSequence(s, l , i); boolean right = true; if(i<n-1) right = isBSTSequence(s, i,r-1); return (left&&right); } public static boolean isBSTSequenceJudge(int[] s) { if(s==null) return false; return isBSTSequence(s,0,s.length); }