|
|
@ -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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|