Simple code in python


  • 0
    A
    def kthSmallest(self, root, k):
        res=[0]
        def recur(root, k):
            if not root:
                return 0
            left_num=recur(root.left, k)
            if left_num==k-1:
                res[0]=root.val
            return 1+left_num+recur(root.right, k-1-left_num)
        recur(root, k)
        return res[0]

Log in to reply
 

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