leetcode 日经贴,Cpp code -Invert Binary Tree
2015-06-13 12:26
453 查看
Invert Binary Tree
/** * 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) return root; invertTree(root->left); invertTree(root->right); TreeNode *tmp = root->left; root->left = root->right; root->right = tmp; return root; } };
相关文章推荐
- C# 调用C++链接库与回调
- C语言的左位移能不能超过8位?
- C++标准库中sstream与strstream的区别详细解析
- (2)风色从零单排《C++ Primer》 一个简单的书店程序
- LIS 最长上升子序列问题 nlgn时间打印其中一个序列
- 在c++程序中调用被c编译器编译后的函数为什么要加extern “C”
- 《C/C++工程师综合练习卷》
- 《C/C++工程师综合练习卷》
- c++的运算符及其优先级
- bit-map简介及其C/C++代码实现
- C++STL中vector容器的用法
- NYOJ 58 最少步数(DFS)
- 一起talk C栗子吧(第十三回:C语言实例--单链表二)
- NYOJ 58 最少步数(BFS)
- xcorr 自相关 c++实现
- C++ delete失败
- 指针和数组——高质量C、C++编程指南
- C++第11章,使用类
- C风格字符串 C++string对象 字符串常量 字符串直接量
- C++在VS2008的IDE环境中操作Excel2007(基础)