-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathpopulating next
More file actions
26 lines (24 loc) · 801 Bytes
/
populating next
File metadata and controls
26 lines (24 loc) · 801 Bytes
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
class Solution:
def connect(self,root):
node=root
while(root):
childhead=None
child=None
while(root):
if root.left:
if childhead is None:
childhead=root.left
child=root.left
else:
child.next=root.left
child=child.next
if root.right:
if childhead is None:
childhead=root.right
child=root.right
else:
child.next=root.right
child=child.next
root=root.next
root=childhead
return node