import java.util.Arrays; public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { int len = sequence.length; if (sequence == null || len == 0) return false; return isBST(sequence); } public boolean isBST(int [] sequence) { int mid = 0, len = sequence.length; if (len <= 1) { return true; } for (; sequence[mid] < sequence[len - 1]; mid++); for (int i = mid; i < len - 1; i++) if (sequence[i] < sequence[len - 1]) return false; return isBST(Arrays.copyOfRange(sequence, 0, mid)) && isBST(Arrays.copyOfRange(sequence, mid, len - 1)); } }