Invert Binary Tree 颠倒二叉树
来源:互联网 发布:淘宝联盟登陆不上去 编辑:程序博客网 时间:2024/06/10 08:55
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1
颠倒二叉树即对树做镜像了。
核心思想是:
1. 左右子树互换。
2. 左右子树本身也要做镜像。
递归求解
代码:
public class InvertBinaryTree { public TreeNode invertTree(TreeNode root) { if (root == null) { return root; } TreeNode temp = invertTree(root.left); root.left = invertTree(root.right); root.right = temp; return root; }}
1 0
- Invert Binary Tree 颠倒二叉树
- 翻转二叉树(Invert Binary Tree)
- 二叉树反转(Invert Binary Tree )
- [Java]Invert Binary Tree翻转二叉树
- Invert Binary Tree(翻转二叉树)
- LintCode --invert-binary-tree(翻转二叉树)
- Invert Binary Tree 二叉树反转
- [LeetCode][二叉树]Invert Binary Tree
- 226. Invert Binary Tree 翻转二叉树
- Invert Binary Tree(反转二叉树)
- 226. Invert Binary Tree | 翻转二叉树
- 反转二叉树(Invert Binary Tree)
- LeetCode Invert Binary Tree 翻转二叉树
- 【LeetCode】Invert Binary Tree 翻转二叉树
- 翻转二叉树(Invert Binary Tree)
- 树-Invert Binary Tree(翻转二叉树)
- LeetCode OJ 之 Invert Binary Tree(反转二叉树)
- leetcode 226 Invert Binary Tree 翻转二叉树
- 如何设置远程桌面连接
- 虚函数和纯虚函数的区别
- java解析xml数据的四种方式
- GitHub第三方资源库整理(OC篇)
- 一个Android项目中各目录介绍
- Invert Binary Tree 颠倒二叉树
- 内部类实现多重继承
- python程序的option
- 下拉刷新超简单
- Sublime-Text2使用技巧
- 怎么用Navicat 进行服务器监控
- Android Studio小技巧 cast快捷键
- iOS 开发过程中遇到的Bug和Warning收录(持续更新)
- SwipeMenuListview源码解析