1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { if(sequence.length==0){ return false; } return Recursion(sequence,0,sequence.length-1); } public boolean Recursion(int [] sequence,int start,int root) { if(start>=root){ return true; } int i = root; while(i>start&&sequence[i-1]>sequence[root]){ i } for (int j = start; j < i-1; j++) { if(sequence[j]>sequence[root]){ return false; } } return Recursion(sequence,start,i-1)&&Recursion(sequence,i,root-1); } }
|