题解 | #数组中重复的数字#
二叉树的下一个结点
http://www.nowcoder.com/practice/9023a0c988684a53960365b889ceaf5e
暴力解
直接用pNode找到根节点
进行中序遍历
在返回的列表中找到对应的下一个值
# class TreeLinkNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
# self.next = None
class Solution:
def inorder(self,root,order):
if root:
self.inorder(root.left,order)
order.append(root)
self.inorder(root.right,order)
def GetNext(self, pNode):
order=[]
root=pNode
while root.next:
root=root.next
self.inorder(root,order)
for i in range(len(order)-1):
if pNode==order[i]:
return None if i==len(order)-1 else order[i+1]
# write code here