leetcode[226]:Invert Binary Tree
来源:互联网 发布:exchange邮箱域名 编辑:程序博客网 时间:2024/06/11 22:06
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.
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;}
递归交换左右子树,注意空的情况。
0 0
- Leetcode[226]-Invert Binary Tree
- LeetCode 226 Invert Binary Tree
- Invert Binary Tree - LeetCode 226
- leetcode[226]:Invert Binary Tree
- leetcode 226: Invert Binary Tree
- Leetcode 226 Invert Binary Tree
- leetcode-226-Invert Binary Tree
- leetcode 226 :Invert Binary Tree
- LeetCode 226Invert Binary Tree
- leetCode #226 Invert Binary Tree
- [LeetCode 226] Invert Binary Tree
- Leetcode #226 Invert Binary Tree
- leetcode 226: Invert Binary Tree
- leetcode: (226) Invert Binary Tree
- LeetCode 226----Invert Binary Tree
- LeetCode 226: Invert Binary Tree
- leetcode 226--Invert Binary Tree
- 【LEETCODE】226-Invert Binary Tree
- Android 音量调节方法
- Android—Activity的四种启动模式
- 将栈S中的元素逆置,使用额外的一个栈L和非数组变量
- leetcode:Invert Binary Tree
- 已知s="(XYZ)+*",t="(X+Z)*Y",利用联接,求子串和转换等基本运算,将s转化为t
- leetcode[226]:Invert Binary Tree
- Populating Next Right Pointers in Each Node II
- Qt4学习(3)——用定时器循环播放图片
- linux命令10--file
- 使用Apache的ab工具进行压力测试
- alsa和oss声音系统比较
- uva580(数学题)
- 编写算法,对给定的字符串str,返回其最长重复子串及其下标位置
- [安卓]手机管家(四)自定义属性