标签:第k小 遍历 color kth 思路 二叉搜索树 ret pre div
1 class Solution: 2 # 返回对应节点TreeNode 3 def KthNode(self, pRoot, k): 4 # write code here 5 stack = [] 6 while stack or pRoot: 7 if pRoot: 8 stack.append(pRoot) 9 pRoot = pRoot.left 10 else: 11 pRoot=stack.pop() 12 k-=1 13 if k == 0: 14 return pRoot 15 pRoot=pRoot.right
2019-12-31 21:26:57
标签:第k小 遍历 color kth 思路 二叉搜索树 ret pre div
原文地址:https://www.cnblogs.com/NPC-assange/p/12127549.html