MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / connect

Method connect

Tree/PopulatingNextRightPointersInEachNodeII.py:55–76  ·  view source on GitHub ↗
(self, root)

Source from the content-addressed store, hash-verified

53 # @param root, a tree link node
54 # @return nothing
55 def connect(self, root):
56 if not root:
57 return
58
59 current = [root]
60 next_nodes = []
61
62 while current or next_nodes:
63 for i in current:
64 if i.left:
65 if next_nodes:
66 next_nodes[-1].next = i.left
67
68 next_nodes.append(i.left)
69 if i.right:
70 if next_nodes:
71 next_nodes[-1].next = i.right
72
73 next_nodes.append(i.right)
74
75 current = next_nodes
76 next_nodes = []
77

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected