root, left child, right child를 가진 binary tree가 있다고 가정할때 root의 value가 각 children values의 합과 같으면 true, 그렇지 않으면 false를 return한다.
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def checkTree(self, root: Optional[TreeNode]) -> bool:
return root.val == root.left.val+root.right.val;
'👩💻Developer > Leetcode' 카테고리의 다른 글
[Easy][Python] Check if Two String Arrays are Equivalent (0) | 2022.11.20 |
---|---|
[Easy][Python] Range Sum of BST (0) | 2022.10.28 |
[Easy][Python] Count of Matches in Tournament (0) | 2022.10.23 |
[Easy][Python] Defanging an IP Address (0) | 2022.10.23 |
[Easy][Python] Build Array from Permutation (0) | 2022.10.23 |
댓글