# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None import copy class Solution: # 返回二維列表,內部每一個列表表示找到的路徑 def FindPath(self, root, expectNumber): # write code here results=[] if root==None: return [] elif root.left==None and root.right==None and expectNumber==root.val: return [[root.val]] else: left=self.FindPath(root.left,expectNumber-root.val) right=self.FindPath(root.right,expectNumber-root.val) for iterm in left+right: results.append([root.val]+iterm) return results