[LeetCode]Path Sum II
2015-07-28 20:31
393 查看
太简单,不解释
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param {TreeNode} root # @param {integer} sum # @return {integer[][]} def pathSum(self, root, sum): if not root: return [] res = [] self.dfs(root, sum, [], res) return res def dfs(self, root, sum, ls, res): if not root.left and not root.right: if root.val == sum: ls.append(root.val) res.append(ls) if root.left: self.dfs(root.left, sum-root.val, ls+[root.val], res) if root.right: self.dfs(root.right, sum-root.val, ls+[root.val], res)
相关文章推荐
- 面试题26_带随机指针的链表复制
- 在Linux中运行Nancy应用程序
- Android开发的基础知识点
- 多校3 1011 Work
- hdu 5288 OO’s Sequence(two point + rmq)
- 【汇总】UNP第一个程序daytime端口开启。。。。
- PAT (Advanced Level) 1068. Find More Coins (30) DFS+剪枝 或 动态规划
- Java学习之路0728(十二)(Class类、反射、Annotation功能注解)
- HDOJ 1896 Stones(优先队列)
- APP首次启动引导界面和启动界面设置——iOS开发
- 【面试加分项】java异常处理之try_catch_finally
- IOS被遗忘的知识
- OC中 static 与 const 的作用
- Activity里添加ViewGroup ViewGroup里添加ViewGroup
- tinyxml使用笔记与总结 http://www.cppblog.com/elva/archive/2008/04/24/47907.html
- hdu 5319 Painter
- Reorder List
- 判断单链表是否有环以及环的连接点
- 百练2757最长上升子序列
- IndexError: list index out of range的错误原因