Finding K Smallest Element in BST Python (Why does this solution not work)

Viewed 20

This prints the correct value though returns None.

def kthSmallest(self, root, k, current):
    if root.left == None:
        current = current + 1
        if current == k:
            print(root.val)   #this prints the correct value 
            return root.val   #this returns None 
        else:
            self.kthSmallest(root.right, k, current)
    else:
        self.kthSmallest(root.left, k, current)
0 Answers
Related