Skip to content

Commit 1c9bb01

Browse files
authored
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy