Please help in debug


  • 0
    S
    def kthSmallest(self, root, k):
            """
            :type root: TreeNode
            :type k: int
            :rtype: int
            """
            if not root:
                return None
            self.c = 1
            self.res = None
            def helper(root, k):
                if not root:
                    return None
                helper(root.left, k)
                if k == self.c:
                    self.res = root.val
                    return 
                else:
                    self.c += 1
                helper(root.right, k)
            helper(root, k)
            return self.res
    

    Anyone please help in debug error ? I am seeing incorrect answer


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.