python写剑指offer每次提交都是返回非0错误

python写剑指offer每次提交都是返回非0错误, 请问怎么提交,具体的格式是什么
例如:重建二叉树
我的代码
class Solution:
    # 返回构造的TreeNode根节点
    def reConstructBinaryTree(self, pre, tin:list):
        print(pre, tin)
        if len(pre) == 0 or len(pre) == 0:
            return None
        # 先序遍历中的第一个元素为根
        root = TreeNode(pre[0])
        # 在tin中寻找root对应的下标
        for i, v in enumerate(tin):
            if v == root.val:
                index = i
                # if index == 0:
                #     index += 1
                # 左子树
                new_pre = pre[1:index + 1]
                new_tin = tin[0:index]
                root.left = self.reConstructBinaryTree(new_pre, new_tin)
                # 右子树
                new_pre = pre[index + 1:len(pre)]
                new_tin = tin[index + 1:len(tin)]
                root.right = self.reConstructBinaryTree(new_pre, new_tin)
        return root


#Python#
全部评论
返回值用return 别用print   注意格式
点赞 回复 分享
发布于 2019-09-21 15:39

相关推荐

爱喝奶茶的垂耳兔拥抱太阳:感觉项目和实习没有技术亮点和难点,单纯说了自己干了啥
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务