Leetcode 437 跑不通这条测试用例
以下是我的代码:
class Solution {
public int pathSum(TreeNode root, int targetSum) {
if (root == null) return 0;
int res = 0;
res += findPath(root, targetSum);
return res + pathSum(root.left, targetSum) + pathSum(root.right, targetSum);
}
private int findPath(TreeNode node, int num) {
if (node == null) return 0;
int res = 0;
if (node.val == num) res += 1;
return res + findPath(node.left, num - node.val) + findPath(node.right, num - node.val);
}
}
但是在跑这条测试用例时出现了wrong answer
root =
[1000000000,1000000000,null,294967296,null,1000000000,null,1000000000,null,1000000000],
targetSum =
0
是不是因为int型数值溢出了呢?可以把findPath的输入改成long型吗?