3 ms·
The root is still the root, but everything else is just flipped: https://leetcode.com/problems/invert-binary-tree/ https://leetcode.com/problems/invert-binary-t
by Arcuru 5y ago
The root is still the root, but everything else is just flipped: https://leetcode.com/problems/invert-binary-tree/ https://leetcode.com/problems/invert-binary-tree/
It is also extremely simple:
TreeNode* invertTree(TreeNode* root) {
if (root) {
invertTree(root->left);
invertTree(root->right);
std::swap(root->left, root->right);
}
return root;
}