/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */publicclassSolution{publicTreeNodeinvertTree(TreeNoderoot){if(root==null)returnroot;// swap left,rightTreeNodetmp=root.left;root.left=root.right;root.right=tmp;invertTree(root.left);invertTree(root.right);returnroot;}}