Given the root of a binary tree, invert the tree, and return its root.
Inverting a binary tree means swapping every left child with its corresponding right child, for all nodes in the tree.
Each node has a val (integer value), a left pointer, and a right pointer. Leaf nodes point to null on both sides.
root = [4, 2, 7, 1, 3, 6, 9][4, 7, 2, 9, 6, 3, 1]root = [2, 1, 3][2, 3, 1]root = [1][1]The number of nodes in the tree is in the range [0, 100]-100 <= Node.val <= 100Expected time complexity: O(n)Run your code to see results
Use Cmd+Enter to run