import java.util.*;
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* }
*/
public class Solution {
/**
*
* @param root TreeNode类
* @param sum int整型
* @return bool布尔型
*/
boolean flag=false;
public boolean hasPathSum (TreeNode root, int sum) {
// write code here
if(root==null) return false;
find(root,sum);
return flag;
}
public void find(TreeNode root,int sum){
if(root.left!=null)
find(root.left,sum-root.val);
if(root.right!=null)
find(root.right,sum-root.val);
if(root.left==null&&root.right==null&&sum==root.val)
flag=true;
}
}
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* }
*/
public class Solution {
/**
*
* @param root TreeNode类
* @param sum int整型
* @return bool布尔型
*/
boolean flag=false;
public boolean hasPathSum (TreeNode root, int sum) {
// write code here
if(root==null) return false;
find(root,sum);
return flag;
}
public void find(TreeNode root,int sum){
if(root.left!=null)
find(root.left,sum-root.val);
if(root.right!=null)
find(root.right,sum-root.val);
if(root.left==null&&root.right==null&&sum==root.val)
flag=true;
}
}