Invert a binary tree.
Have you met this question in a real interview?
Yes
Example
1 1 / \ / \ 2 3 => 3 2 / \ 4 4
public class Solution { /** * @param root: a TreeNode, the root of the binary tree * @return: nothing */ public void invertBinaryTree(TreeNode root) { // write your code here if(root == null){ return; } TreeNode temp = root.left; root.left = root.right; root.right = temp; invertBinaryTree(root.left); invertBinaryTree(root.right); } }