Skip to content

Commit 6d50bed

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c515a5f commit 6d50bed

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

data_structures/binary_tree/binary_tree_node_sum.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Sum of all nodes in a binary tree.
33
4-
Python implementation:
4+
Python implementation:
55
O(n) time complexity - Recurses through :meth:`depth_first_search`
66
with each element.
7-
O(n) space complexity - At any point in time maximum number of stack
7+
O(n) space complexity - At any point in time maximum number of stack
88
frames that could be in memory is `n`
99
"""
1010

@@ -62,15 +62,14 @@ def depth_first_search(self, node: Node | None) -> int:
6262
if node is None:
6363
return 0
6464
return node.value + (
65-
self.depth_first_search(node.left) +
66-
self.depth_first_search(node.right)
65+
self.depth_first_search(node.left) + self.depth_first_search(node.right)
6766
)
6867

6968
def node_sum(self) -> int:
7069
return self.depth_first_search(self.tree)
7170

71+
7272
if __name__ == "__main__":
7373
import doctest
7474

7575
doctest.testmod()
76-

0 commit comments

Comments
 (0)