Easy
https://leetcode.com/problems/path-sum-iii/
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 |
2019.9.13 没做出来,参考 https://blog.csdn.net/fuxuemingzhu/article/details/71097135
方法:
DFS + DFS(一个 DFS 本身会调用自己,同时也调用另一个 DFS)
1 |
class (object): |
类似题目:
Path Sum
Path Sum II
Path Sum IV
Longest Univalue Path
近期评论