From 4b921601df03a6863759124f587ae370832ac1f1 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Thu, 16 Jul 2020 09:46:28 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9B=B8?= =?UTF-8?q?=E5=85=B3.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Algorithm/剑指 Offer/二叉树相关.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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); + } +} +``` +