public TreeNode invertTree(TreeNode root) {
if(root==null) return root;
Stack<TreeNode> stack =new Stack();
stack.push(root);
while(!stack.isEmpty()){
TreeNode node = stack.pop();
TreeNode tmp=node.left;
node.left=node.right;
node.right=tmp;
if(node.left!=null) stack.push(node.left);
if(node.right!=null) stack.push(node.right);
}
return root;
}
public TreeNode invertTree(TreeNode root) {
if(root==null) return null;
TreeNode tmp=root.left;
root.left=root.right;
root.right=tmp;
invertTree(root.left);
invertTree(root.right);
return root;
}