输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果。如果是则返回 true,否则返回 false。假设输入的数组的任意两个数字都互不相同。 如下: 5 \ 2 6 \ 1 3
示例1
输入
[1,6,3,2,5]
输出
false
示例2
输入
[1,3,2,6,5]
输出
true
加载中...
import java.util.*; public class Solution { /** * 后序遍历二叉搜索树 * @param postorder int整型一维数组 * @return bool布尔型 */ public boolean verifyPostorder (int[] postorder) { // write code here } }
class Solution { public: /** * 后序遍历二叉搜索树 * @param postorder int整型一维数组 * @param postorderLen int postorder数组长度 * @return bool布尔型 */ bool verifyPostorder(int* postorder, int postorderLen) { // write code here } };
# # 后序遍历二叉搜索树 # @param postorder int整型一维数组 # @return bool布尔型 # class Solution: def verifyPostorder(self , postorder ): # write code here
/** * 后序遍历二叉搜索树 * @param postorder int整型一维数组 * @return bool布尔型 */ function verifyPostorder( postorder ) { // write code here } module.exports = { verifyPostorder : verifyPostorder };
# # 后序遍历二叉搜索树 # @param postorder int整型一维数组 # @return bool布尔型 # class Solution: def verifyPostorder(self , postorder ): # write code here
package main /** * 后序遍历二叉搜索树 * @param postorder int整型一维数组 * @return bool布尔型 */ func verifyPostorder( postorder []int ) bool { // write code here }
/** * 后序遍历二叉搜索树 * @param postorder int整型一维数组 * @param postorderLen int postorder数组长度 * @return bool布尔型 */ bool verifyPostorder(int* postorder, int postorderLen ) { // write code here }
[1,6,3,2,5]
false
[1,3,2,6,5]
true