112. Path Sum
2016-05-04 08:52
148 查看
Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum代码
public class Solution { public boolean hasPathSum(TreeNode root, int sum) { if(root == null){ return false; } if(root.left == null && root.right == null && root.val == sum){ return true; } return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val); } }
相关文章推荐
- 233. Number of Digit One
- 第一课程序框架的构建——C#计算器编程教学
- 关于oracle 实例名大小写的问题
- php 函 数
- 为什么UDP有时比TCP更有优势?
- WebMvcConfigurationSupport
- 汉诺塔
- 《java入门第一季》之面向对象(匿名对象)
- Retrofit2.0+网络框架HTTP实战
- 《java入门第一季》之面向对象(匿名对象)
- 虚拟机已死,容器才是未来?
- array used and char`s array and string`s array
- am335x开发板的疑问以及解答
- 浅谈盒模型
- Android 模拟器的创建
- ajax
- count2array_count_values .php
- wildfly10 append postgresql driver & datasource
- 14商软2班软件工程各组团队照
- Project facet Java version 1.7 is not supported.