public boolean hasPathSum(TreeNode root, int sum) {
if (root == null){
return false;
}
if (root.left == null && root.right == null){
return sum == root.val;
}
return hasPathSum(root.left,sum-root.val) || hasPathSum(root.right,sum-root.val);
}
leetcode 112 路径总和
最新推荐文章于 2024-04-26 09:02:35 发布