From 7c4ddc633cb39d03c4f661f9d149b7766cbbc9fb Mon Sep 17 00:00:00 2001 From: Ronald Ngounou <74538524+ronaldngounou@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:38:43 -0400 Subject: [PATCH 1/6] test: Add unit tests --- .../binary_tree/binary_tree_path_sum.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index a3fe9ca7a7e2..90205b593cc5 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -50,6 +50,26 @@ class BinaryTreePathSum: >>> tree.right.right = Node(10) >>> BinaryTreePathSum().path_sum(tree, 8) 2 + >>> BinaryTreePathSum().path_sum(None, 0) + 0 + >>> BinaryTreePathSum().path_sum(tree, 0) + 0 + + The second tree looks like this + + >>> tree2 = Node(0) + >>> tree2.left = Node(5) + >>> tree2.right = Node(5) + 0 + / \ + 5 5 + >>> BinaryTreePathSum().path_sum(tree, 5) + 2 + >>> BinaryTreePathSum().path_sum(tree, -1) + 0 + >>> BinaryTreePathSum().path_sum(tree, 0) + 1 + """ target: int From 1ee8199cd3c529bc72300552df95e54fffc5fa8d Mon Sep 17 00:00:00 2001 From: Ronald Ngounou <74538524+ronaldngounou@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:43:10 -0400 Subject: [PATCH 2/6] test: Add successful tests in binaree_tree_path_sum --- .../binary_tree/binary_tree_path_sum.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index 90205b593cc5..43df30f2e308 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -56,18 +56,19 @@ class BinaryTreePathSum: 0 The second tree looks like this - - >>> tree2 = Node(0) - >>> tree2.left = Node(5) - >>> tree2.right = Node(5) 0 / \ 5 5 - >>> BinaryTreePathSum().path_sum(tree, 5) + + >>> tree2 = Node(0) + >>> tree2.left = Node(5) + >>> tree2.right = Node(15) + + >>> BinaryTreePathSum().path_sum(tree2, 5) 2 - >>> BinaryTreePathSum().path_sum(tree, -1) + >>> BinaryTreePathSum().path_sum(tree2, -1) 0 - >>> BinaryTreePathSum().path_sum(tree, 0) + >>> BinaryTreePathSum().path_sum(tree2, 0) 1 """ From 8ea7d2a5857574253478a6eb6624df09a98d8471 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:48:25 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/binary_tree/binary_tree_path_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index 43df30f2e308..d8e6f06123ee 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -54,7 +54,7 @@ class BinaryTreePathSum: 0 >>> BinaryTreePathSum().path_sum(tree, 0) 0 - + The second tree looks like this 0 / \ @@ -63,7 +63,7 @@ class BinaryTreePathSum: >>> tree2 = Node(0) >>> tree2.left = Node(5) >>> tree2.right = Node(15) - + >>> BinaryTreePathSum().path_sum(tree2, 5) 2 >>> BinaryTreePathSum().path_sum(tree2, -1) From e82eab972f83d6d94cf6df2c3e4ca16448f9e19f Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sat, 30 Aug 2025 11:37:52 +0300 Subject: [PATCH 4/6] Update binary_tree_path_sum.py --- data_structures/binary_tree/binary_tree_path_sum.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index d8e6f06123ee..ecd2b338d659 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -56,21 +56,20 @@ class BinaryTreePathSum: 0 The second tree looks like this - 0 - / \ - 5 5 + 0 + / \ + 5 5 >>> tree2 = Node(0) >>> tree2.left = Node(5) >>> tree2.right = Node(15) >>> BinaryTreePathSum().path_sum(tree2, 5) - 2 + 1 >>> BinaryTreePathSum().path_sum(tree2, -1) 0 >>> BinaryTreePathSum().path_sum(tree2, 0) 1 - """ target: int From 89763814d38dec918d99930822fa54039eb8242f Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sat, 30 Aug 2025 11:45:44 +0300 Subject: [PATCH 5/6] Update binary_tree_path_sum.py --- data_structures/binary_tree/binary_tree_path_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index ecd2b338d659..d52d9861def4 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -62,10 +62,10 @@ class BinaryTreePathSum: >>> tree2 = Node(0) >>> tree2.left = Node(5) - >>> tree2.right = Node(15) + >>> tree2.right = Node(5) >>> BinaryTreePathSum().path_sum(tree2, 5) - 1 + 3 >>> BinaryTreePathSum().path_sum(tree2, -1) 0 >>> BinaryTreePathSum().path_sum(tree2, 0) From 0981035a91b76725c30440eb10b58a9d3a1a9fd9 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sat, 30 Aug 2025 11:46:17 +0300 Subject: [PATCH 6/6] Update binary_tree_path_sum.py --- data_structures/binary_tree/binary_tree_path_sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index d52d9861def4..8477690c777a 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -65,7 +65,7 @@ class BinaryTreePathSum: >>> tree2.right = Node(5) >>> BinaryTreePathSum().path_sum(tree2, 5) - 3 + 4 >>> BinaryTreePathSum().path_sum(tree2, -1) 0 >>> BinaryTreePathSum().path_sum(tree2, 0)