Skip to content

Commit

Permalink
Create populating next
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush292003 authored Oct 23, 2022
1 parent 1d71f63 commit 1811c2e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions populating next
Original file line number Diff line number Diff line change
@@ -0,0 +1,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

0 comments on commit 1811c2e

Please sign in to comment.