Given the root of a binary tree, replace the value of each node with the sum of all its cousins’ values.
Two nodes in a binary tree are considered cousins if they are at the same depth but have different parents.
If a node has no cousins, its value should be replaced with
Return the root of the modified tree.
Constraints:
The number of nodes in the tree is in the range
Node.val
Given the root of a binary tree, replace the value of each node with the sum of all its cousins’ values.
Two nodes in a binary tree are considered cousins if they are at the same depth but have different parents.
If a node has no cousins, its value should be replaced with
Return the root of the modified tree.
Constraints:
The number of nodes in the tree is in the range
Node.val