forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path62.py
29 lines (26 loc) · 771 Bytes
/
62.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding:utf-8 -*-
class TreeLinkNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
self.next = None
class Solution:
def GetNext(self, pNode):
# write code here
if pNode.right is not None:
rightNode = pNode.right
while rightNode.left is not None:
rightNode = rightNode.left
return rightNode
else:
parent = pNode.next
curNode = pNode
if parent == None:
return None
while parent.right == curNode:
curNode = parent
parent = parent.next
if parent == None:
return None
return parent