Update 二叉树相关.md

master
Omooo 4 years ago
parent d7579f91b1
commit 4b921601df
  1. 26
      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);
}
}
```

Loading…
Cancel
Save