# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def kthLargest(self, root: TreeNode, k: int) -> int:
count = 0
def dfs(node):
if node is None:
return False, None
state, val = dfs(node.right)
if state:
return state, val
nonlocal count
count += 1
if count == k:
return True, node.val
return dfs(node.left)
return dfs(root)[1]