```
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# @param {TreeNode} root
# @param {integer} k
# @return {integer}
def kthSmallest(self, root, k):
if root.left==None and root.right==None:
return root.val
lowest=root
leftseq=[root]
while lowest.left!=None:
lowest=lowest.left
leftseq.append(lowest)
leftseq.pop()
while k>1:
if lowest.right==None:
lowest=leftseq.pop()
else:
lowest=lowest.right
while lowest.left!=None:
leftseq.append(lowest)
lowest=lowest.left
k-=1
return lowest.val
```