deno.land / x / masx200_leetcode_test@10.6.5 / binary-tree-pruning / index.ts
1234567891011import { TreeNode } from "../mod.ts";
export default function pruneTree(root: TreeNode | null): TreeNode | null { if (!root) return null; const left = pruneTree(root.left); const right = pruneTree(root.right); if (root.val === 0 && !left && !right) return null;
return new TreeNode(root.val, left, right);}
Version Info