Skip to content

Commit cb10f70

Browse files
authored
Create root-equals-sum-of-children.py
1 parent 3238611 commit cb10f70

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/root-equals-sum-of-children.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# Definition for a binary tree node.
5+
class TreeNode(object):
6+
def __init__(self, val=0, left=None, right=None):
7+
pass
8+
9+
10+
# tree
11+
class Solution(object):
12+
def checkTree(self, root):
13+
"""
14+
:type root: Optional[TreeNode]
15+
:rtype: bool
16+
"""
17+
return root.val == root.left.val+root.right.val

0 commit comments

Comments
 (0)