We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5fe27f5 commit 969d7d3Copy full SHA for 969d7d3
README.md
@@ -574,6 +574,8 @@ https://leetcode.cn/problems/basic-calculator/
574
575
https://leetcode.cn/problems/evaluate-reverse-polish-notation/
576
577
+https://leetcode.cn/problems/sum-of-root-to-leaf-binary-numbers/
578
+
579
#### 安装教程
580
581
1. 安装`deno`
sum-of-root-to-leaf-binary-numbers/index.ts
@@ -0,0 +1,10 @@
1
+import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
2
3
+export default function sumRootToLeaf(root: TreeNode | null, sum = 0): number {
4
+ return !root
5
+ ? 0
6
+ : (!root.left) && (!root.right)
7
+ ? sum * 2 + root.val
8
+ : sumRootToLeaf(root.left, sum * 2 + root.val) +
9
+ sumRootToLeaf(root.right, sum * 2 + root.val);
10
+}
0 commit comments