Skip to content

Commit 3c1351c

Browse files
committed
refactor(algorithms, arrays, two-sum): enqueue nodes if present
1 parent 2d4cfb5 commit 3c1351c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

algorithms/arrays/two_sum/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ def two_sum_find_target(root: BinaryTreeNode, k: int) -> bool:
9797
seen.add(curr.data)
9898

9999
# enqueue the left and right children of the current node
100-
queue.append(curr.left)
101-
queue.append(curr.right)
100+
if curr.left:
101+
queue.append(curr.left)
102+
if curr.right:
103+
queue.append(curr.right)
102104

103105
# if we reach here, we have not found two nodes that add up to the target
104106
return False

0 commit comments

Comments
 (0)