# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right classSolution: defkthSmallest(self, root: Optional[TreeNode], k: int) -> int: queue, ans = [root], [] while queue: tmp =[] for node in queue: if node.left: tmp.append(node.left) if node.right: tmp.append(node.right) ans.append(node.val) queue = tmp ans = sorted(ans) return ans[k-1]