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

Class Solution

Tree/PopulatingNextRightPointersInEachNode.py:58–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected