Created
October 6, 2019 00:26
-
-
Save sheldonrobinson/fdb35bd51eace06014db3629178c5190 to your computer and use it in GitHub Desktop.
CodeSignal Solution kthSmallestInBST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Binary trees are already defined with this interface: | |
# class Tree(object): | |
# def __init__(self, x): | |
# self.value = x | |
# self.left = None | |
# self.right = None | |
def kthSmallestInBST(t, k): | |
def inorder(r): | |
return inorder(r.left) + [r.value] + inorder(r.right) if r else [] | |
return inorder(t)[k - 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment