Skip to content

Commit 773eeba

Browse files
committed
refactor(binary-trees, zig-zag-level-order): add else condition
1 parent 0a9a7ab commit 773eeba

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

datastructures/trees/binary/tree/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def zig_zag_level_order(self) -> List[List[BinaryTreeNode]]:
694694
# we use a queue to traverse the tree level by level
695695
queue = deque([self.root])
696696

697-
# starting at one, because the root node is already in the result
697+
# starting at zero, because the tree levels are counted from 0
698698
level_number = 0
699699

700700
while queue:
@@ -715,9 +715,9 @@ def zig_zag_level_order(self) -> List[List[BinaryTreeNode]]:
715715
# if level number is odd reverse the list, every odd level is reversed
716716
if level_number % 2 == 1:
717717
result.append(current_level[::-1])
718-
719-
# otherwise add the current level
720-
result.append(current_level)
718+
else:
719+
# otherwise add the current level
720+
result.append(current_level)
721721

722722
# add a level and proceed
723723
level_number += 1

0 commit comments

Comments
 (0)