LeetCode: Invert Binary Tree
来源:互联网 发布:科尔沁风干牛肉 知乎 编辑:程序博客网 时间:2024/05/29 16:05
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
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.
/** * 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) return NULL; TreeNode *temp = root->left; root->left = invertTree(root->right); root->right = invertTree(temp); return root; }};
0 0
- [leetcode] Invert Binary Tree
- [LeetCode]Invert Binary Tree
- leetcode:Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode | Invert Binary Tree
- leetcode--Invert Binary Tree
- [leetcode] Invert Binary Tree
- [LeetCode] Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode : Invert Binary Tree
- [LeetCode] Invert Binary Tree
- [Leetcode]Invert Binary Tree
- LeetCode: Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode: Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode || Invert Binary Tree
- LeetCode:Invert Binary Tree
- Spring中的拦截器
- Visual Studio: MSB3073 error exited with code 1
- 本地数据注入设想(测试功能)
- springAop简单介绍
- 彻底理解JS原型以及构造函数
- LeetCode: Invert Binary Tree
- magento模块实例开发,前后台开发,表单提交案例
- FFMpeg 实现从视频中提取音轨
- Android Sensor详解(3)porting drvier
- 变分自编码VAE(variational autoencoder)及Keras 实现
- Android进阶之自定义控件二
- Android studio Building gradle info 过久,无反应
- Android 三种解析Json分别 原生态 Goson FastJson
- Spring Boot,IntelliJ IDEA,JSP,启动报错java.lang.NoClassDefFoundError: javax/servlet/ServletContext