Skip to content

Commit 5601147

Browse files
committed
Runtime: 305 ms (Top 5.46%) | Memory: 15.4 MB (Top 49.03%)
1 parent 3f26642 commit 5601147

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/algorithms/P/Populating Next Right Pointers in Each Node II/Populating Next Right Pointers in Each Node II.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Runtime: 305 ms (Top 5.46%) | Memory: 15.4 MB (Top 49.03%)
12
"""
23
# Definition for a Node.
34
class Node(object):
@@ -31,7 +32,7 @@ def findRightMostFromRoot(self, rootLevelInfo, requiredLevel, currentRight):
3132
if currentRight:
3233
if currentRight.right:
3334
return currentRight.right
34-
if currentRight.left:
35+
if currentRight.left:
3536
return currentRight.left
3637
root, rootlevel = rootLevelInfo
3738
rightMost = self.findRightMost(root, rootlevel, requiredLevel)
@@ -69,11 +70,11 @@ def stitch(self, root):
6970
currentLeft = self.findLeftMostFromRoot(rightRootStart, 1, None)
7071
currentRight = self.findRightMostFromRoot(leftRootStart, 1, None)
7172
while currentLeft and currentRight:
72-
currentRight.next = currentLeft
73+
currentRight.next = currentLeft
7374
connectLevel += 1
7475
currentLeft = self.findLeftMostFromRoot(rightRootStart, connectLevel, currentLeft)
7576
currentRight = self.findRightMostFromRoot(leftRootStart, connectLevel, currentRight)
76-
77+
7778
self.stitch(root.left)
7879
self.stitch(root.right)
7980
def connect(self, root):
@@ -84,4 +85,4 @@ def connect(self, root):
8485
if not root:
8586
return root
8687
self.stitch(root)
87-
return root
88+
return root

0 commit comments

Comments
 (0)