LeetCode 226: Invert Binary Tree
2015-09-17 13:27
423 查看
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode* invertTree(TreeNode* root) { TreeNode *temp; if(root){ temp = root->right; root->right = root->left; root->left = temp; invertTree(root->left); invertTree(root->right); } return root; } };
这题和遍历类似,遍历的时候先把左右子树交换,就得出反转的二叉树。
相关文章推荐
- 【Android】HttpUrlConnection AsyncTack
- c++中的string常用函数用法总结
- python处理Unicode规则
- dynamic web module version
- MySQL修改root密码
- Junit Test problem
- 手机上滑动,显示滚动条
- Spring+Spring MVC+Hibernate增查(使用注解)
- 统计URL出现的频次
- 覆盖了一层view 下面一层点击效果还是有效的
- The service ‘xxx’ configured for WCF is not registered with the Autofac container
- Android网络请求--服务器端从环境搭建到发布过程
- git解决rebase冲突
- 陈华:可能再过半年,这一波创业潮就彻底消失了
- HDU 4289 Control
- 封装
- win8系统如何可以查看无线网络流量?win8查看无线网络流量的方法
- unity3d实现视频播放
- memset栈空间出现段错误
- c语言中.h文件的作用