Skip to content

2236. Root Equals Sum of Children 👎

  • Time: $O(1)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  bool checkTree(TreeNode* root) {
    return root->val == root->left->val + root->right->val;
  }
};
1
2
3
4
5
class Solution {
  public boolean checkTree(TreeNode root) {
    return root.val == root.left.val + root.right.val;
  }
}
1
2
3
class Solution:
  def checkTree(self, root: TreeNode | None) -> bool:
    return root.val == root.left.val + root.right.val