Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Following is the Binary Tree node structure.
- class BinaryTreeNode:
- def __init__(self, data):
- self.data = data
- self.left = None
- self.right = None
- from collections import deque
- def kPathSum(root, k):
- ans=[]
- q=[]
- def dfs(x):
- if not x: return
- q.append(x.data)
- dfs(x.left)
- dfs(x.right)
- val=0
- for i in range(len(q)-1,-1,-1):
- val+=q[i]
- if val==k:ans.append(q[i:][:])
- q.pop()
- dfs(root)
- return ans
Advertisement
Add Comment
Please, Sign In to add comment