Invert Binary Tree
2015-11-02 21:09
267 查看
题目:
Invert a binary tree.
to
解析:
Invert a binary tree.
4 / \ 2 7 / \ / \ 1 3 6 9
to
4 / \ 7 2 / \ / \ 9 6 3 1
解析:
/** * 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) { if(root!=NULL) { TreeNode* tmp=root->left; root->left=root->right; root->right=tmp; invertTree(root->left); invertTree(root->right); } return root; } };
相关文章推荐
- HDU-2795-Billboard
- mysql截取字符串
- Lesson 7 Matrix-matrix and matrix-vector multiplication
- 子进程和父进程的关系和示例
- iOS 心得九:应用缓存的查看和清除
- bit、byte、位、字节、汉字的关系
- OpenGL一些函数详解(二)
- WPF学习(一)--布局控件简介
- 玩转树莓派--图形界面登陆
- 个人之对于Block的初探究
- 使用ubuntu15.04手动搭建LNMP服务器框架
- poj 1006 暴搜
- Win7系统的最佳浏览效果的调节方法
- NeoTalen的由来
- HDU 5517 (ACM 2015 沈阳) Triple [树状数组]
- 选择器
- 产生随机数
- Linux命令大观
- [Android Lint] xxx is not translated in xxx 的解决方法
- #pragma分析