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 81806ea commit 78996cdCopy full SHA for 78996cd
1001-1500/1022.py
@@ -0,0 +1,17 @@
1
+# Definition for a binary tree node.
2
+# class TreeNode:
3
+# def __init__(self, val=0, left=None, right=None):
4
+# self.val = val
5
+# self.left = left
6
+# self.right = right
7
+class Solution:
8
+ def sumRootToLeaf(self, root: Optional[TreeNode]) -> int:
9
+ def dfs(node,path):
10
+ if not node:
11
+ return 0
12
+ path = (path<<1)+node.val
13
+ if not node.left and not node.right:
14
+ return path
15
+ else:
16
+ return dfs(node.left, path) + dfs(node.right, path)
17
+ return dfs(root,0)
0 commit comments