leetcode-- Invert Binary Tree
来源:互联网 发布:支付宝软件 编辑:程序博客网 时间:2024/06/12 01:12
反转二叉树。
解题思路:左右节点互换,然后递归调用即可。
java版本:
public class Solution { public TreeNode invertTree(TreeNode root) { if(root==null) {return root;} TreeNode tmp=invertTree(root.left); root.left=invertTree(root.right); root.right=tmp; return root; }}
c++版本:
class Solution {public: TreeNode* invertTree(TreeNode* root) { if(root==NULL) return NULL; TreeNode* temp=root->left; root->left=root->right; root->right=temp; root->left=invertTree(root->left); root->right=invertTree(root->right); return root; }};
1 0
- [leetcode] Invert Binary Tree
- [LeetCode]Invert Binary Tree
- leetcode:Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode | Invert Binary Tree
- leetcode--Invert Binary Tree
- [leetcode] Invert Binary Tree
- [LeetCode] Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode : Invert Binary Tree
- [LeetCode] Invert Binary Tree
- [Leetcode]Invert Binary Tree
- LeetCode: Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode: Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode || Invert Binary Tree
- LeetCode:Invert Binary Tree
- 55.EasyCountDownTextureView
- 停止JQuery Ajax请求
- iOS xib创建tableViewController顶部留白问题
- Thinking in java 笔记1
- Android开发入门与实战之Android应用安装卸载
- leetcode-- Invert Binary Tree
- Qt_几个错误
- C++虚继承(四) --- /d1 reportSingleClassLayout插入看类内存布局
- Qt Creater 制作汽车仪表盘
- Linux errno参照表
- 每天进步一点点——五分钟理解一致性哈希算法(consistent hashing)
- android中实现view的更新有两组方法
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- C++创建使用静态动态库