c*e
2 楼
read4网上到处有啊 本来就不是它家原创
Binary Tree Upside Down 顾名思义
Binary Tree Upside Down 顾名思义
c*e
3 楼
Binary Tree Upside Down 我猜是这个
http://www.careercup.com/question?id=6266917077647360
http://www.careercup.com/question?id=6266917077647360
w*p
4 楼
你能share钱么?
b*g
5 楼
就是这道。题目毕竟不是他家原创的,觉得没什么泄露不泄露的。
我的理解是这15/49刀买的是书,以及那10题使用OJ来测试你解答正确与否的service费
。这两样是LC自己的东西。
【在 c*******e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Binary Tree Upside Down 我猜是这个
: http://www.careercup.com/question?id=6266917077647360
我的理解是这15/49刀买的是书,以及那10题使用OJ来测试你解答正确与否的service费
。这两样是LC自己的东西。
【在 c*******e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Binary Tree Upside Down 我猜是这个
: http://www.careercup.com/question?id=6266917077647360
j*3
7 楼
1337 大牛不乖了,哼哼
b*g
8 楼
还没看过答案,我写了个递归做法,可能还有更好的解。递归的思路:
假设当前节点为r,需要先递归将r->left为根的子树upside down并返回最右叶子节点n
。然后将r->right接到n->left,将r接到n->right。由于此时新树的最右叶子节点为r
,返回r供上层递归使用。代码里的newRoot是为了返回整个树upside down后的新的根。
class Solution {
public:
TreeNode *upsideDownBinaryTree(TreeNode *root) {
TreeNode *temp, *newRoot = NULL;
temp = buildUpsideDownBT(root, newRoot);
return newRoot;
}
TreeNode *buildUpsideDownBT(TreeNode *root, TreeNode *&newRoot) {
if(!root) return root;
if(!root->left && !root->right) {
newRoot = root;
return root;
}
TreeNode *parent = buildUpsideDownBT(root->left, newRoot);
parent->left = root->right;
parent->right = root;
root->left = root->right = NULL;
return parent->right;
}
};
【在 j**********3 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 1337 大牛不乖了,哼哼
假设当前节点为r,需要先递归将r->left为根的子树upside down并返回最右叶子节点n
。然后将r->right接到n->left,将r接到n->right。由于此时新树的最右叶子节点为r
,返回r供上层递归使用。代码里的newRoot是为了返回整个树upside down后的新的根。
class Solution {
public:
TreeNode *upsideDownBinaryTree(TreeNode *root) {
TreeNode *temp, *newRoot = NULL;
temp = buildUpsideDownBT(root, newRoot);
return newRoot;
}
TreeNode *buildUpsideDownBT(TreeNode *root, TreeNode *&newRoot) {
if(!root) return root;
if(!root->left && !root->right) {
newRoot = root;
return root;
}
TreeNode *parent = buildUpsideDownBT(root->left, newRoot);
parent->left = root->right;
parent->right = root;
root->left = root->right = NULL;
return parent->right;
}
};
【在 j**********3 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 1337 大牛不乖了,哼哼
j*y
9 楼
好思路
点n
r
根。
【在 b******g 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 还没看过答案,我写了个递归做法,可能还有更好的解。递归的思路:
: 假设当前节点为r,需要先递归将r->left为根的子树upside down并返回最右叶子节点n
: 。然后将r->right接到n->left,将r接到n->right。由于此时新树的最右叶子节点为r
: ,返回r供上层递归使用。代码里的newRoot是为了返回整个树upside down后的新的根。
: class Solution {
: public:
: TreeNode *upsideDownBinaryTree(TreeNode *root) {
: TreeNode *temp, *newRoot = NULL;
: temp = buildUpsideDownBT(root, newRoot);
: return newRoot;
点n
r
根。
【在 b******g 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 还没看过答案,我写了个递归做法,可能还有更好的解。递归的思路:
: 假设当前节点为r,需要先递归将r->left为根的子树upside down并返回最右叶子节点n
: 。然后将r->right接到n->left,将r接到n->right。由于此时新树的最右叶子节点为r
: ,返回r供上层递归使用。代码里的newRoot是为了返回整个树upside down后的新的根。
: class Solution {
: public:
: TreeNode *upsideDownBinaryTree(TreeNode *root) {
: TreeNode *temp, *newRoot = NULL;
: temp = buildUpsideDownBT(root, newRoot);
: return newRoot;
相关阅读
h1b transfer有两天假日间隔没有工资怎么办?offer base低了怎么要价也不要否认, 几十岁的人还被迫做题确实是耻辱想着有h1b还是稳妥些Re: 在Apple 做硬件什么体验?啥时候大家线下聚聚啊刚才去看了芳华 每天一发在此今年狗家硬件的refresh怎样每天一发 我们要用刷题绑架所有公司的面试今天电面的时候一个问题G 家换组到cloud怎么样刷题刷过面试就能胜任工作吗?蚂蚁金服 值得归吗?Potential Changes to High-Skilled Immigration Programs in圣诞期间公司shut down 去哪里刷题?为什么说做前端低级?开车 cross a solid white line on a California road, 会拿请教老鸟一个猎头/hr常问的*经典*问题归和不归的offerbracket 出来了 大家可以不用离婚了 (转载)