为什么Leetcode上problem108内提供的辅助函数有问题呢?

我做了一道108. Convert Sorted Array to Binary Search Tree, with Python 3

run code总是显示AttributeError

去playground debug,看到了报错信息里,一个把结果打印出来的辅助函数treeNodeToString是这样的:

def treeNodeToString(root):
    if not root:
        return "[]"
    output = ""
    queue = [root]
    current = 0
    while current != len(queue):
        node = queue[current]
        current = current + 1

        if not node:
            output += "null, "
            continue

        output += str(node.val) + ", "
        queue.append(node.left)
        queue.append(node.right)
    return "[" + output[:-2] + "]"

反正我是没有看明白……

后来我自己写了一个类似功能的函数,终于在playground中调试成功了……

然而回到problem界面我又伤心了,,我要怎么修改会插入代码的code snippet呢?呵呵呵……

桑心……

现在就想弄明白到底咋回事儿……

后续:AttributeError是犯了一个很挫很小白的错误引起的,虽然答案已经被接受了,但我依然看不懂这个auxiliary function......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值