54. 二叉搜索树的第n个节点
二叉搜索树的第k个结点
http://www.nowcoder.com/questionTerminal/ef068f602dde4d28aab2b210e859150a
利用中序遍历即可
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # 返回对应节点TreeNode def KthNode(self, pRoot, k): # write code here self.res=[] self.dfs(pRoot) return self.res[k-1] if 0<k<=len(self.res) else None def dfs(self,pRoot): if not pRoot: return None if pRoot: self.dfs(pRoot.left) self.res.append(pRoot) self.dfs(pRoot.right)