题目描述:
代码:
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def kthLargest(self, root, k):
self.count=k
#记录数值是否找到的标志位,避免不必要的递归操作
self.find=False
def findValue(node):
if node==None or self.find:
return None
findValue(node.right)
self.count=self.count-1
if self.count==0:
self.value=node.val
self.find=True
return None
if self.find==False:
findValue(node.left)
findValue(root)
return self.value