226. 翻转二叉树
作者:互联网
public TreeNode invertTree(TreeNode root) {
if (root == null) {
return null;
}
invertTree(root.left);
invertTree(root.right);
swapChildren(root);
return root;
}
private void swapChildren(TreeNode root) {
TreeNode tmp = root.left;
root.left = root.right;
root.right = tmp;
}
}
标签:right,TreeNode,invertTree,二叉树,226,left,root,翻转 来源: https://blog.csdn.net/mynameisgt/article/details/122757218