public boolean hasPathSum(TreeNode root, int sum) {
    	if (root == null)
    		return false;
    	if (root.left == null && root.right == null)
    	{
    		if (sum == root.val)
    			return true;
    		else
    			return false;
    	}
    	
    	boolean ret = false;
    	if (root.left != null)
    		ret = ret || hasPathSum(root.left, sum - root.val);
    	if (root.right!= null)
    		ret = ret || hasPathSum(root.right, sum - root.val);
    	
    	return ret;
    }