Leetcode - K SUM Problem
112. Path Sum[E]
https://leetcode.com/problems/path-sum/
Description
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
Note: A leaf is a node with no children.
Example:
Given the below binary tree and sum = 22,
1 | 5 |
return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
Solution
113. Path Sum II[M]
https://leetcode.com/problems/path-sum-ii/
Description
Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.
Note: A leaf is a node with no children.
Example:
Given the below binary tree and sum = 22,
1 | 5 |
Return:
1 | [ |
Solution
1 |
437. Path Sum III[M]
https://leetcode.com/problems/path-sum-iii/
Description
You are given a binary tree in which each node contains an integer value.
Find the number of paths that sum to a given value.
The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes).
The tree has no more than 1,000 nodes and the values are in the range -1,000,000 to 1,000,000.
Example:
1 | root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8 |
Solution
1 |





