text: # 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
  class Solution:
      def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
          self.k = k
          self.inorder(root)
          return self.ans
  
      def inorder(self, root):
          if not root:
              return 
          self.inorder(root.left)
          if self.k == 1:
              self.ans = root.val
              self.k = 0
              return 
          else:
              self.k -= 1
          self.inorder(root.right)
  