美文网首页
2019-08-24 LeetCode 230. 二叉搜索树中第

2019-08-24 LeetCode 230. 二叉搜索树中第

作者: mztkenan | 来源:发表于2019-08-24 21:48 被阅读0次

    其实很快的,但是由于a=0的情况造成排查错误好久。
    找不到错误的时候还是靠人工去推导

    class Solution:
        def __init__(self):
            self.index=0
    
        def kthSmallest(self, root: TreeNode, k: int) -> int:
            if not root:return None
            a=self.kthSmallest(root.left,k)
            if a!=None:return a  # 错在这里,a=0的时候认为为空,不能写if a
            self.index+=1
            if self.index==k:return root.val
            b=self.kthSmallest(root.right,k)
            return b
    

    相关文章

      网友评论

          本文标题:2019-08-24 LeetCode 230. 二叉搜索树中第

          本文链接:https://www.haomeiwen.com/subject/mrhcectx.html