```
class Solution(object):
def kthSmallest(self, root, k):
"""
:type root: TreeNode
:type k: int
:rtype: int
"""
parents = []
node = root
while parents or node:
if node:
parents.append(node)
node = node.left
else:
node = parents.pop()
if k > 1:
k -= 1
else:
return node.val
node = node.right
```