data_structures.binary_tree.binary_tree_path_sum ================================================ .. py:module:: data_structures.binary_tree.binary_tree_path_sum .. autoapi-nested-parse:: Given the root of a binary tree and an integer target, find the number of paths where the sum of the values along the path equals target. Leetcode reference: https://leetcode.com/problems/path-sum-iii/ Classes ------- .. autoapisummary:: data_structures.binary_tree.binary_tree_path_sum.BinaryTreePathSum data_structures.binary_tree.binary_tree_path_sum.Node Module Contents --------------- .. py:class:: BinaryTreePathSum The below tree looks like this 10 / \ 5 -3 / \ \ 3 2 11 / \ \ 3 -2 1 >>> tree = Node(10) >>> tree.left = Node(5) >>> tree.right = Node(-3) >>> tree.left.left = Node(3) >>> tree.left.right = Node(2) >>> tree.right.right = Node(11) >>> tree.left.left.left = Node(3) >>> tree.left.left.right = Node(-2) >>> tree.left.right.right = Node(1) >>> BinaryTreePathSum().path_sum(tree, 8) 3 >>> BinaryTreePathSum().path_sum(tree, 7) 2 >>> tree.right.right = Node(10) >>> BinaryTreePathSum().path_sum(tree, 8) 2 .. py:method:: depth_first_search(node: Node | None, path_sum: int) -> None .. py:method:: path_sum(node: Node | None, target: int | None = None) -> int .. py:attribute:: paths :value: 0 .. py:attribute:: target :type: int .. py:class:: Node(value: int) A Node has value variable and pointers to Nodes to its left and right. .. py:attribute:: left :type: Node | None :value: None .. py:attribute:: right :type: Node | None :value: None .. py:attribute:: value