Skip to content

Instantly share code, notes, and snippets.

@sheldonrobinson
Created October 6, 2019 00:26
Show Gist options
  • Save sheldonrobinson/fdb35bd51eace06014db3629178c5190 to your computer and use it in GitHub Desktop.
Save sheldonrobinson/fdb35bd51eace06014db3629178c5190 to your computer and use it in GitHub Desktop.
CodeSignal Solution kthSmallestInBST
#
# 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