diff --git a/blogs/Algorithm/剑指 Offer/二叉树相关.md b/blogs/Algorithm/剑指 Offer/二叉树相关.md index cc05e89..a46d742 100644 --- a/blogs/Algorithm/剑指 Offer/二叉树相关.md +++ b/blogs/Algorithm/剑指 Offer/二叉树相关.md @@ -484,3 +484,29 @@ class Solution { } ``` +#### [33. 二叉搜索树的后序遍历序列](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) + +```java +class Solution { + + public boolean verifyPostorder(int[] postorder) { + return helper(postorder, 0, postorder.length - 1); + } + + private boolean helper(int[] order, int i, int j) { + if (i >= j) { + return true; + } + int p = i; + while (order[p] < order[j]) { + p++; + } + int m = p; + while (order[p] > order[j]) { + p++; + } + return p == j && helper(order, i, m - 1) && helper(order, m, j - 1); + } +} +``` +