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;
}
}
相关文章
- 09-30P3884 [JLOI2009]二叉树问题(LCA)
- 09-30Skill如何翻转一个list
- 09-30236. Lowest Common Ancestor of a Binary Tree 二叉树的最低公共祖先
- 09-30【Leetcode】1123. Lowest Common Ancestor of Deepest Leaves(二叉树最深叶子结点的公共父节点)
- 09-30LeetCode236. Lowest Common Ancestor of a Binary Tree(二叉树的最近公共祖先)
- 09-30Tree Summing UVA - 112 二叉树
- 09-30Leetcode606.Construct String from Binary Tree根据二叉树创建字符串
- 09-30606. Construct String from Binary Tree 从二叉树中构建字符串
- 09-30opencv学习笔记3——图像缩放,翻转和阈值分割
- 09-30[置顶] hdu 1890 伸展树区间翻转