题解 | #二叉搜索树的后序遍历序列 双指针#
二叉搜索树的后序遍历序列
https://www.nowcoder.com/practice/a861533d45854474ac791d90e447bafd
import java.util.*; public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { if (sequence.length == 0){ return false; } return Fuc(sequence); } public static boolean Fuc(int[] sequence) { if (sequence.length <= 1) { return true; } int left = 0; int right = sequence.length - 2; int head = sequence[sequence.length - 1]; while (sequence[left] < head) { left++; } while (right >= 0 && sequence[right] > head) { right--; } if (left != right + 1) { return false; } else { return Fuc(Arrays.copyOfRange(sequence, 0, left)) && Fuc(Arrays.copyOfRange(sequence, left, sequence.length - 1)); } } }