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

相关推荐

06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
07-11 11:10
门头沟学院 Java
请问各位大三兄弟们跟hr说多久实习时间到时候可以提前跑路吗?
程序员小白条:问就是六个月以上,可以一年,实习都这样,你入职后想跑就跑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务