一、leetcode地址
https://leetcode.com/problems/kth-smallest-element-in-a-bst/
二、问题描述
三、代码实现
语言:Python3
代码:
class Solution:
def ldr(self,root):
if root:
return self.ldr(root.left)+[root.val]+self.ldr(root.right)
else:
return []
def kthSmallest(self, root: TreeNode, k: int) -> int:
l1 = self.ldr(root)
print(l1)
return l1[k-1]