-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path437.path-sum-iii.py
More file actions
33 lines (26 loc) · 811 Bytes
/
437.path-sum-iii.py
File metadata and controls
33 lines (26 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
count = 0
l = list()
sum = 0
def pathSum(self, root: TreeNode, sum: int) -> int:
self.sum = sum
self.findPath(root)
return self.count
def findPath(self,root):
if root == None:
return
self.l.append(root.val)
self.findPath(root.left)
self.findPath(root.right)
temp = 0
for x in range(len(self.l)-1,-1,-1):
temp += self.l[x]
if temp == self.sum:
self.count += 1
self.l.pop(len(self.l)-1)