deno.land / x / masx200_leetcode_test@10.6.5 / path-sum / index.ts
12345678910111213141516import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
export default function hasPathSum( root: TreeNode | null, targetSum: number,): boolean { if (!root) { return false; }
if (root.val == targetSum && !root.left && !root.right) return true;
return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);}
Version Info