leetcode[226]:Invert Binary Tree
2015-06-12 20:22
387 查看
Invert Binary Tree
Trivia:
This problem was inspired by this original tweet by Max Howell:
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
递归交换左右子树,注意空的情况。
Trivia:
This problem was inspired by this original tweet by Max Howell:
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
struct TreeNode* invertTree(struct TreeNode* root) { struct TreeNode *tmp1; if(!root) return root; if(!root->left && !root->right) return root; if( root->left && !root->right) { root->right=invertTree(root->left);; root->left = NULL; } else if( !root->left && root->right) { root->left=invertTree(root->right); root->right = NULL; } else if( root->left && root->right) { tmp1 = root->left; root->left = invertTree(root->right); root->right = invertTree(tmp1); } return root; }
递归交换左右子树,注意空的情况。
相关文章推荐
- 命令行快速技巧:如何定位一个文件
- cmd tree命令 以树形格式罗列文件
- 推荐8款jQuery轻量级树形Tree插件
- tree 以树形格式罗列文件
- EasyUI Tree+Asp.net实现权限树或目录树导航的简单实例
- E3 tree 1.6在Firefox下显示问题的修复方法
- js树形控件脚本代码
- MYSQL的binary解决mysql数据大小写敏感问题的方法
- Spark Decision Tree
- 带check的treeView
- extjs 4 treepanel locked and expand
- JQuery EasyUI 实现tree的右键菜单
- flex tree 的两个小技巧
- Tree.log
- gnome文件管理器(nautilus)树形结构文件窗口 多窗口
- 排序binary tree
- eclipse C/C++ 问题(launch failed,binary not found)
- launch failed.Binary not found in Linux/Ubuntu解决方案
- python递归实现Easyui combotree树
- InnoDB--------查询IOT B+ Tree的高度