226. Invert Binary Tree
做法就是:
如果root是null,返回
swap左右两树(用tmp作为第三个容器),然后对左右子树递归
返回root
1 public TreeNode invertTree(TreeNode root) { 2 if(root == null) { 3 return null; 4 } 5 TreeNode tmp = root.left; 6 root.left = root.right; 7 root.right = tmp; 8 invertTree(root.left); 9 invertTree(root.right); 10 return root; 11 }