EasyLeetCode #226Trees
Invert Binary Tree
Given the root of a binary tree, invert the tree, and return its root.
Constraints
The number of nodes in the tree is in the range [0, 100], -100 <= Node.val <= 100
Given the root of a binary tree, invert the tree, and return its root.
The number of nodes in the tree is in the range [0, 100], -100 <= Node.val <= 100
Recursively swap left and right children for each node. Can also be done iteratively with BFS/DFS.
def invertTree(root):
if not root:
return None
root.left, root.right = root.right, root.left
invertTree(root.left)
invertTree(root.right)
return root