Given the root of a binary tree, return true if you can partition the tree into two trees with equal sums of values after removing exactly one edge on the original tree.
Example 1:

Input: root = [5,10,10,null,null,2,3] Output: true
Example 2:

Input: root = [1,2,10,null,null,2,20] Output: false Explanation: You cannot split the tree into two trees with equal sums after removing exactly one edge on the tree.
Constraints:
- The number of nodes in the tree is in th

该博客探讨了LeetCode 663题,涉及如何检查一棵二叉树是否能通过删除一条边形成两个和相等的子树。博主介绍了将二叉树问题类比于数组处理的方法,利用前缀和思想,通过前序遍历或后序遍历收集所有子树的和,并存储在集合中。最后检查树的总和是否可被2整除,以及总和的一半是否存在于集合内,以此判断是否存在符合条件的边。
最低0.47元/天 解锁文章
1554

被折叠的 条评论
为什么被折叠?



