Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c9bb01

Browse files
add one approach
1 parent aedd7dc commit 1c9bb01

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎Kangli/Trees/pathSumII.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution(object):
2+
def pathSum(self, root, sum):
3+
result = []
4+
self.dfs(root, sum, [], result)
5+
return result
6+
7+
def dfs(self, node, sum, path, res):
8+
if not node:
9+
return
10+
if not node.left and not node.right:
11+
if node.val == sum:
12+
res.append(path + [node.val])
13+
self.dfs(node.left, sum - node.val, path + [node.val], res)
14+
self.dfs(node.right, sum - node.val, path + [node.val], res)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /