/** * Definition for a binary tree node. * function TreeNode(val, left, right) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } */ /** * @param {TreeNode} root * @param {number} targetSum * @return {boolean} */ var hasPathSum = function(root, targetSum) { let result = false let dfs = (data, presum, tar) => { if (data) { presum = data.val + presum if (!data.left && !data.right) { if (presum == tar) { result = true } } dfs(data.left, presum, tar) dfs(data.right, presum, tar) } } dfs(root, 0, targetSum) return result };
尼采般地抒情
音乐盒
站点信息
文章总数目:
321
篇
已运行时间:
1782
天
评论区