226. Invert Binary Tree
来源:互联网 发布:java socket异步接收 编辑:程序博客网 时间:2024/06/06 16:52
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1Trivia:
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 * leftNode=invertTree(root->left);
TreeNode * rightNode=invertTree(root->right);
root->left=rightNode;
root->right=leftNode;
return root;
}
0 0
- 226.Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 机器学习入门系列02,Regression 回归:案例研究
- 网站的海量数据和高并发的解决方案(一)
- mysql 数据库集群
- IIS发布网站
- Android基础知识07
- 226. Invert Binary Tree
- BaseAdapter的封装和实现
- spring boot csrf
- SurfaceView、SurfaceHolder与Surface
- BZOJ 2671(Calc-数论反演)
- 下载网页
- Lintcode 罗马数字转整数
- 蓝桥杯 历届试题 错误票据
- Android基础知识08