Solution to "Kth Smallest Element in a BST" on Leetcode.
1# Definition for a binary tree node.
2# class TreeNode:
3# def __init__(self, val=0, left=None, right=None):
4# self.val = val
5# self.left = left
6# self.right = right
7class Solution:
8 def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
9
10 def tree_to_list(root) -> list:
11 if not root:
12 return []
13
14 return tree_to_list(root.right) + [root.val] + tree_to_list(root.left)
15
16 tree_list = tree_to_list(root)
17 return tree_list[-k]
Solution to "Count Number of Texts" question on Leetcode.
Solution to "Second Minimum Node In a Binary Tree" on Leetcode.