

【解题思路】

class Solution {
public boolean verifyPostorder(int[] postorder) {
return recur(postorder, 0, postorder.length - 1);
}
boolean recur(int[] postorder, int i, int j) {
if(i >= j) return true;
int p = i;
while(postorder[p] < postorder[j]) p++;
int m = p;
while(postorder[p] > postorder[j]) p++;
return p == j && recur(postorder, i, m - 1) && recur(postorder, m, j - 1);
}
}
该博客探讨了一个Java解决方案,用于验证给定的数组是否为一棵二叉树的后序遍历结果。通过递归方法检查后序遍历的正确性,该算法涉及到中缀分隔点的确定和递归子树的验证。
522

被折叠的 条评论
为什么被折叠?



