由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - leetcode交了钱的能share一下题么?
相关主题
help: leetcode "Recover Binary Search Tree" -- 附代码Find the node with given value in binary tree in in-order
发现一个很恶心的基础问题Flatten Binary Tree to Linked List的recursive解法
问一个题目leetcode的OJ也会有错吗??
为啥有两个case不对??Binary Tree Maximum Path Sumleetcode 运行结果和eclipse不一样???
Leetcode bst max path-----is this solution correct?这个inorder traversal 有错嘛,为什么leetcode 总报memory limit exceed?
check if a binary tree is a valid binary search tree求教Leetcode题目:Lowest Common Ancestor
判断是不是binary search tree-leetcode关于leetcode上的一道题
[leetcode] Maximum Depth of Binary Tree一个题:给定一个节点,找right neighbor
相关话题的讨论汇总
话题: root话题: treenode话题: newroot话题: upside话题: right
进入JobHunting版参与讨论
1 (共1页)
j**********3
发帖数: 3211
1
虽然很猥琐,但是,,,穷阿
c*******e
发帖数: 621
2
read4网上到处有啊 本来就不是它家原创
Binary Tree Upside Down 顾名思义
c*******e
发帖数: 621
3
Binary Tree Upside Down 我猜是这个
http://www.careercup.com/question?id=6266917077647360
w**p
发帖数: 4080
4
你能share钱么?
b******g
发帖数: 3616
5
就是这道。题目毕竟不是他家原创的,觉得没什么泄露不泄露的。
我的理解是这15/49刀买的是书,以及那10题使用OJ来测试你解答正确与否的service费
。这两样是LC自己的东西。

【在 c*******e 的大作中提到】
: Binary Tree Upside Down 我猜是这个
: http://www.careercup.com/question?id=6266917077647360

j**********3
发帖数: 3211
6
Binary Tree Upside Down怎么作?

【在 c*******e 的大作中提到】
: read4网上到处有啊 本来就不是它家原创
: Binary Tree Upside Down 顾名思义

j**********3
发帖数: 3211
7
1337 大牛不乖了,哼哼
b******g
发帖数: 3616
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 的大作中提到】
: 1337 大牛不乖了,哼哼
j*****y
发帖数: 9
9
好思路

点n
r
根。

【在 b******g 的大作中提到】
: 还没看过答案,我写了个递归做法,可能还有更好的解。递归的思路:
: 假设当前节点为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;

1 (共1页)
进入JobHunting版参与讨论
相关主题
一个题:给定一个节点,找right neighborLeetcode bst max path-----is this solution correct?
请教LEETCODE讲解部分的LCA一道题的变种。。check if a binary tree is a valid binary search tree
电面没做出题。郁闷!!判断是不是binary search tree-leetcode
F家面经[leetcode] Maximum Depth of Binary Tree
help: leetcode "Recover Binary Search Tree" -- 附代码Find the node with given value in binary tree in in-order
发现一个很恶心的基础问题Flatten Binary Tree to Linked List的recursive解法
问一个题目leetcode的OJ也会有错吗??
为啥有两个case不对??Binary Tree Maximum Path Sumleetcode 运行结果和eclipse不一样???
相关话题的讨论汇总
话题: root话题: treenode话题: newroot话题: upside话题: right