add #8 python implement
This commit is contained in:
parent
23f7a48929
commit
25d27ddaca
@ -532,7 +532,24 @@ public TreeLinkNode GetNext(TreeLinkNode pNode) {
|
||||
```
|
||||
|
||||
```python
|
||||
|
||||
def GetNext(self, pNode):
|
||||
# write code here
|
||||
# pNode is None
|
||||
if not pNode:
|
||||
return pNode
|
||||
if pNode.right:
|
||||
node = pNode.right
|
||||
while node.left:
|
||||
node = node.left
|
||||
return node
|
||||
else:
|
||||
while pNode.next:
|
||||
parent = pNode.next
|
||||
if parent.left == pNode:
|
||||
return parent
|
||||
pNode = pNode.next
|
||||
# pNode not have the next node
|
||||
return None
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user