Skip to content

Commit 53aec4d

Browse files
authored
not a stack oops
1 parent 860d987 commit 53aec4d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: 226-invert_binary_tree.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def invertTree(self, root):
3030

3131
return root
3232

33+
3334
"""
3435
Iterative
3536
@@ -45,18 +46,18 @@ def invertTree(self, root):
4546
if not root:
4647
return None
4748

48-
stack = deque()
49-
stack.append(root)
49+
queue = deque()
50+
queue.append(root)
5051

51-
while stack:
52-
node = stack.popleft()
52+
while queue:
53+
node = queue.popleft()
5354

5455
#swap the left & right children with each other
5556
node.left, node.right = node.right, node.left
5657

5758
if node.left:
58-
stack.append(node.left)
59+
queue.append(node.left)
5960
if node.right:
60-
stack.append(node.right)
61+
queue.append(node.right)
6162

6263
return root

0 commit comments

Comments
 (0)