Skip to content

Commit 4b81b38

Browse files
committed
update
1 parent 63db8f7 commit 4b81b38

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@
782782
337| [House Robber III](https://leetcode.com/problems/house-robber-iii/) | [Python](./leetcode_python/Recursion/house-robber-iii.py) | _O(n)_ _O(h)_| Medium|amazon, google| AGAIN (not start)
783783
395| [Longest Substring with At Least K Repeating Characters](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/) |[Python](./leetcode_python/Recursion/longest-substring-with-at-least-k-repeating-characters.py) | _O(n)_ | _O(1)_ | Medium |`AGAIN`,`recursion`, `good trick`,`fb`| AGAIN************ (4)
784784
404| [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/) | [Python](./leetcode_python/Recursion/sum-of-left-leaves.py) | _O(n)_ | _O(h)_ | Easy, tree, bfs, dfs |`fb`| OK**** (3)
785-
437| [Path Sum III](https://leetcode.com/problems/path-sum-iii/) | [Python](./leetcode_python/Recursion/path-sum-iii.py) | _O(n)_ | _O(h)_ |Easy|`good trick`,`UBER`, `AMAZON`, `fb`| AGAIN*** (3)
785+
437| [Path Sum III](https://leetcode.com/problems/path-sum-iii/) | [Python](./leetcode_python/Recursion/path-sum-iii.py) | _O(n)_ | _O(h)_ |Medium|`good trick`,`UBER`, `AMAZON`, `fb`| AGAIN*** (3)
786786
544| [Output Contest Matches](https://leetcode.com/problems/output-contest-matches/) | [Python](./leetcode_python/Recursion/output-contest-matches.py) | _O(n)_ | _O(n)_ | Medium || AGAIN
787787
549 | [Binary Tree Longest Consecutive Sequence II](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii/) | [Python](./leetcode_python/Recursion/binary-tree-longest-consecutive-sequence-ii.py) | _O(n)_ | _O(h)_ | Medium |🔒| AGAIN (not start)
788788
669| [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree/) | [Python](./leetcode_python/Recursion/trim-a-binary-search-tree.py) | _O(n)_ | _O(h)_ | Medium |good basic, BST, dfs, recursion,`amazon`| AGAIN******* (4)

leetcode_python/Recursion/path-sum-iii.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
"""
2+
3+
437. Path Sum III
4+
Medium
5+
6+
Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.
7+
8+
The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes).
9+
10+
11+
12+
Example 1:
13+
14+
15+
Input: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8
16+
Output: 3
17+
Explanation: The paths that sum to 8 are shown.
18+
Example 2:
19+
20+
Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
21+
Output: 3
22+
23+
24+
Constraints:
25+
26+
The number of nodes in the tree is in the range [0, 1000].
27+
-109 <= Node.val <= 109
28+
-1000 <= targetSum <= 1000
29+
30+
"""
31+
132
# V0
233
# IDEA : BFS + DFS
334
# => USE BFS FIND EVERY NODE IN THE TREE, AND USE DFS GET THR PATH SUM ON EVERY NODE (FOUND BY BFS)
@@ -179,4 +210,4 @@ def pathSumHelper(root, prev, sum):
179210

180211
return pathSumHelper(root, 0, sum) + \
181212
self.pathSum(root.left, sum) + \
182-
self.pathSum(root.right, sum)
213+
self.pathSum(root.right, sum)

0 commit comments

Comments
 (0)