Python Easy Solution


  • 0
    Z
    class Solution(object):
        def kthSmallest(self, root, k):
            n = [0]
            def dfs(root):
                if root.left and dfs(root.left) == k:
                    return root.left.val
                if root.right and dfs(root.right) == k:
                    return root.right.val
                n[0] += 1
                return n[0]
            return dfs(root)
    

Log in to reply
 

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