var hasPathSum = function(root, targetSum) {
if(root==null)return false;
//判断targetsum和叶子节点的值是否相等
if(root.left==null && root.right==null){
// console.log(targetSum)
return(targetSum==root.val);
// console.log(targetSum,'ppp')
};
// console.log(targetSum,'qqq')
return hasPathSum(root.left,targetSum-root.val) || hasPathSum(root.right,targetSum-root.val)
};
路经总和-JS
最新推荐文章于 2024-08-30 20:29:15 发布