b*n
2 楼
2岁多的小孩今天一直喊腿疼,周日晚上的时候同边的脚被图钉扎了一下,不知道是不
是这个原因?他的破伤风的针follow the schedule. 不知道有没有知道的姐妹说一下
,多谢阿。
是这个原因?他的破伤风的针follow the schedule. 不知道有没有知道的姐妹说一下
,多谢阿。
t*y
3 楼
彻底被律师搞晕了,以前来版上问过J1 waiver后能不能直接递交485,老大的回答是可以的,当时问律师他也说可以,但现在俺的律师又说不一定了,问了学校的国际部,国际部的人说不清楚。版上有没有类似情况的,J1 waiver后一定要转成H1才能交485吗?多谢了!
s*a
6 楼
腿疼,不是脚疼,应该跟图钉没有太大的关系吧。是不是生长疼哟?如果不放心,还是
问问医生吧。
问问医生吧。
d*2
7 楼
我有一个朋友与你类似,J1waiver, 但没有H1
上个月已经FP了,估计马上应该得到绿卡了吧
上个月已经FP了,估计马上应该得到绿卡了吧
j*e
8 楼
小吉找到家了么?
d*t
9 楼
可以用递归,返回值是从该节点出发到leaf的最长路径(可以是个vector)。对于每个
node,比较子节点返回的path,保留长的一条,pass上去。
node,比较子节点返回的path,保留长的一条,pass上去。
b*n
10 楼
我也觉得挺奇怪的,明天问问医生吧。
t*y
11 楼
多谢,多谢。找个律师本来是为了省心,结果现在天天让我操心。
b*n
14 楼
我也觉得挺奇怪的,明天问问医生吧。
s*u
17 楼
int LongestPath(struct Tree * T)
{
if (T->left == NULL && T->right == NULL)
return 0;
return 1 + std::max(LongestPath(T->left), LongestPath(T->right));
}
{
if (T->left == NULL && T->right == NULL)
return 0;
return 1 + std::max
}
t*6
19 楼
可以的。我正准备递485呢,H1还没批下来呢,就用J1。
d*t
21 楼
我这里假设你说的是Binary tree。其它的TREE无非就是子节点多一些,要比较的子
path多一些。
vector* longestpath(node* root)
{
vector* path;
if(root==NULL)
{
path = new vector;
}
else
{
vector* left = longestpath(root->left);
vector* right = longestpath(root->right);
path = left->size()>right->size()?left:right;
path->push_back(root);
}
return path;
}
然后根据要求加个wrapper function就行了
path多一些。
vector
{
vector
if(root==NULL)
{
path = new vector
}
else
{
vector
vector
path = left->size()>right->size()?left:right;
path->push_back(root);
}
return path;
}
然后根据要求加个wrapper function就行了
w*4
22 楼
我妈妈跟我提过,有的小孩在生长的过程中会有疼痛现象(又叫生长痛)。不过最好还
是看一下医生。
是看一下医生。
j*e
24 楼
昨天听说上次跑出来和Chili玩的大血猎就那么丢了,都怪我RP不好,抓不住,哎
d*t
25 楼
要是只是返回长度,每次返回个最长的长度值就行了。either way,复杂度都是O(n)
b*n
26 楼
I will call the Doctor today. Many thanks!
a*t
28 楼
是嘛? 啥时候的事情呀?
pat pat 不是RP不好,可能是没缘份吧~~
pat pat 不是RP不好,可能是没缘份吧~~
i*9
30 楼
我家两岁小孩分不清疼和痒,痒也说成疼,我给她挠挠就好了。。。
a*o
32 楼
TRP?哈哈
c*2
33 楼
There is a solution at
http://www.ihas1337code.com/search/label/binary%20tree
/** See my comments **/
int maxDepthIterative(BinaryTree *root) {
if (!root) return 0;
stack s;
s.push(root);
int depth = 1, maxDepth = 0;
BinaryTree *prev = NULL;
while (!s.empty()) {
BinaryTree *curr = s.top();
if (!prev || prev->left == curr || prev->right == curr) {
if (curr->left) {
depth++;
s.push(curr->left);
} else if (curr->right) {
depth++;
s.push(curr->right);
}
} else if (curr->left == prev) {
if (curr->right) {
depth++;
s.push(curr->right);
}
} else {
depth--;
s.pop();
}
prev = curr;
if (depth > maxDepth)
maxDepth = depth;
/** At this point, the stack contains the longest reversed path
We can do a reverse copy into a queue;
**/
}
/** The queue will have the longest path **/
return maxDepth;
http://www.ihas1337code.com/search/label/binary%20tree
/** See my comments **/
int maxDepthIterative(BinaryTree *root) {
if (!root) return 0;
stack
s.push(root);
int depth = 1, maxDepth = 0;
BinaryTree *prev = NULL;
while (!s.empty()) {
BinaryTree *curr = s.top();
if (!prev || prev->left == curr || prev->right == curr) {
if (curr->left) {
depth++;
s.push(curr->left);
} else if (curr->right) {
depth++;
s.push(curr->right);
}
} else if (curr->left == prev) {
if (curr->right) {
depth++;
s.push(curr->right);
}
} else {
depth--;
s.pop();
}
prev = curr;
if (depth > maxDepth)
maxDepth = depth;
/** At this point, the stack contains the longest reversed path
We can do a reverse copy into a queue;
**/
}
/** The queue will have the longest path **/
return maxDepth;
w*r
34 楼
我儿子也是,想让我挠挠的时候,都可怜兮兮的喊疼.
b*1
37 楼
生长疼,长个子的时候容易出现,女儿小时候也有
u*b
40 楼
我家也有,弄不明白,下次见儿医问问。
l*e
41 楼
什么是microchip啊!!!!我觉得我们家lele肯定没有
i*e
47 楼
Your solution is basically a bottom-up approach. However, there is a problem
. You are allocating the vectors dynamically, which leaks memory after the
function finishes. How are you going to clean up? There is no easy way.
I know you allocate it dynamically instead of statically is to use pointer
to reference, thus avoiding copy by value for efficiency purposes. Another
problem is you are also using more memory than you should. When you found
the left branch has a greater depth, you don't clean up the right branch,
therefore it is still occupied in memory. If you choose to clean up the
right branch, you end up spending extra time to process the right branch.
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
【在 d*****t 的大作中提到】
: 我这里假设你说的是Binary tree。其它的TREE无非就是子节点多一些,要比较的子
: path多一些。
: vector* longestpath(node* root)
: {
: vector* path;
: if(root==NULL)
: {
: path = new vector;
: }
: else
. You are allocating the vectors dynamically, which leaks memory after the
function finishes. How are you going to clean up? There is no easy way.
I know you allocate it dynamically instead of statically is to use pointer
to reference, thus avoiding copy by value for efficiency purposes. Another
problem is you are also using more memory than you should. When you found
the left branch has a greater depth, you don't clean up the right branch,
therefore it is still occupied in memory. If you choose to clean up the
right branch, you end up spending extra time to process the right branch.
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
【在 d*****t 的大作中提到】
: 我这里假设你说的是Binary tree。其它的TREE无非就是子节点多一些,要比较的子
: path多一些。
: vector
: {
: vector
: if(root==NULL)
: {
: path = new vector
: }
: else
b*n
48 楼
Great to know!
Thanks for all the replies! Now my baby stopped complaining and I think it
is growing pain.
Thanks for all the replies! Now my baby stopped complaining and I think it
is growing pain.
d*t
49 楼
对,应该在不用的时候删除短的那个vector. 但是用递归通常会用到多余的data, 这个
基本上不避
免。至于删除不需要的branch所花的时间并不比用非递归时间多,相当于非递归中把节
点从stack
里一个一个pop出来的过程。
总的来说用非递归通常会快一些,但是写起来会比较麻烦一些,我觉得是各有利弊的~
problem
the
way.
pointer
Another
found
branch,
the
branch.
【在 i**********e 的大作中提到】
: Your solution is basically a bottom-up approach. However, there is a problem
: . You are allocating the vectors dynamically, which leaks memory after the
: function finishes. How are you going to clean up? There is no easy way.
: I know you allocate it dynamically instead of statically is to use pointer
: to reference, thus avoiding copy by value for efficiency purposes. Another
: problem is you are also using more memory than you should. When you found
: the left branch has a greater depth, you don't clean up the right branch,
: therefore it is still occupied in memory. If you choose to clean up the
: right branch, you end up spending extra time to process the right branch.
: 一些常见面试题的答案与总结 -
基本上不避
免。至于删除不需要的branch所花的时间并不比用非递归时间多,相当于非递归中把节
点从stack
里一个一个pop出来的过程。
总的来说用非递归通常会快一些,但是写起来会比较麻烦一些,我觉得是各有利弊的~
problem
the
way.
pointer
Another
found
branch,
the
branch.
【在 i**********e 的大作中提到】
: Your solution is basically a bottom-up approach. However, there is a problem
: . You are allocating the vectors dynamically, which leaks memory after the
: function finishes. How are you going to clean up? There is no easy way.
: I know you allocate it dynamically instead of statically is to use pointer
: to reference, thus avoiding copy by value for efficiency purposes. Another
: problem is you are also using more memory than you should. When you found
: the left branch has a greater depth, you don't clean up the right branch,
: therefore it is still occupied in memory. If you choose to clean up the
: right branch, you end up spending extra time to process the right branch.
: 一些常见面试题的答案与总结 -
n*y
50 楼
嗯,我娃儿折腾的时候就叫腿疼脚疼啥的。其实我觉得他是便秘。
i*e
51 楼
How about this top-down approach?
Basically we cannot avoid copying the current path to longest path every
time we update maxDepth, unless we obtain the value of maxDepth by traversing the entire tree beforehand.
void findLongestPath(BinaryTree *p, int &maxDepth, vector &path
, vector &longestPath) {
if (!p) return;
path.push_back(p);
if (!p->left && !p->right && path.size() > maxDepth) {
maxDepth = path.size();
longestPath = path;
}
findLongestPath(p->left, maxDepth, path, longestPath);
findLongestPath(p->right, maxDepth, path, longestPath);
path.pop_back();
}
vector findLongestPath(BinaryTree *root) {
vector longestPath;
vector path;
int maxDepth = 0;
findLongestPath(root, maxDepth, path, longestPath);
return longestPath;
}
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
【在 d*****t 的大作中提到】
: 对,应该在不用的时候删除短的那个vector. 但是用递归通常会用到多余的data, 这个
: 基本上不避
: 免。至于删除不需要的branch所花的时间并不比用非递归时间多,相当于非递归中把节
: 点从stack
: 里一个一个pop出来的过程。
: 总的来说用非递归通常会快一些,但是写起来会比较麻烦一些,我觉得是各有利弊的~
:
: problem
: the
: way.
Basically we cannot avoid copying the current path to longest path every
time we update maxDepth, unless we obtain the value of maxDepth by traversing the entire tree beforehand.
void findLongestPath(BinaryTree *p, int &maxDepth, vector
, vector
if (!p) return;
path.push_back(p);
if (!p->left && !p->right && path.size() > maxDepth) {
maxDepth = path.size();
longestPath = path;
}
findLongestPath(p->left, maxDepth, path, longestPath);
findLongestPath(p->right, maxDepth, path, longestPath);
path.pop_back();
}
vector
vector
vector
int maxDepth = 0;
findLongestPath(root, maxDepth, path, longestPath);
return longestPath;
}
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
【在 d*****t 的大作中提到】
: 对,应该在不用的时候删除短的那个vector. 但是用递归通常会用到多余的data, 这个
: 基本上不避
: 免。至于删除不需要的branch所花的时间并不比用非递归时间多,相当于非递归中把节
: 点从stack
: 里一个一个pop出来的过程。
: 总的来说用非递归通常会快一些,但是写起来会比较麻烦一些,我觉得是各有利弊的~
:
: problem
: the
: way.
d*t
52 楼
Top down也不错,基本上是在pre-order遍历的同时加上一些变量,传一些参数
traversing the entire tree beforehand.
&path
【在 i**********e 的大作中提到】
: How about this top-down approach?
: Basically we cannot avoid copying the current path to longest path every
: time we update maxDepth, unless we obtain the value of maxDepth by traversing the entire tree beforehand.
: void findLongestPath(BinaryTree *p, int &maxDepth, vector &path
: , vector &longestPath) {
: if (!p) return;
: path.push_back(p);
: if (!p->left && !p->right && path.size() > maxDepth) {
: maxDepth = path.size();
: longestPath = path;
traversing the entire tree beforehand.
&path
【在 i**********e 的大作中提到】
: How about this top-down approach?
: Basically we cannot avoid copying the current path to longest path every
: time we update maxDepth, unless we obtain the value of maxDepth by traversing the entire tree beforehand.
: void findLongestPath(BinaryTree *p, int &maxDepth, vector
: , vector
: if (!p) return;
: path.push_back(p);
: if (!p->left && !p->right && path.size() > maxDepth) {
: maxDepth = path.size();
: longestPath = path;
a*8
53 楼
Depth first, starting from root
or Breadth first
or Breadth first
P*l
54 楼
We cannot avoid bookmarking the path when the we find a local maximum path.
But we can use bit map to keep track the path rather than using vector of
pointers. The bitmap can be as simple as a long integer, 0 is for left child
and 1 is for right child. The current depth needs to be saved in this case.
traversing the entire tree beforehand.
path
【在 i**********e 的大作中提到】
: How about this top-down approach?
: Basically we cannot avoid copying the current path to longest path every
: time we update maxDepth, unless we obtain the value of maxDepth by traversing the entire tree beforehand.
: void findLongestPath(BinaryTree *p, int &maxDepth, vector &path
: , vector &longestPath) {
: if (!p) return;
: path.push_back(p);
: if (!p->left && !p->right && path.size() > maxDepth) {
: maxDepth = path.size();
: longestPath = path;
But we can use bit map to keep track the path rather than using vector of
pointers. The bitmap can be as simple as a long integer, 0 is for left child
and 1 is for right child. The current depth needs to be saved in this case.
traversing the entire tree beforehand.
path
【在 i**********e 的大作中提到】
: How about this top-down approach?
: Basically we cannot avoid copying the current path to longest path every
: time we update maxDepth, unless we obtain the value of maxDepth by traversing the entire tree beforehand.
: void findLongestPath(BinaryTree *p, int &maxDepth, vector
: , vector
: if (!p) return;
: path.push_back(p);
: if (!p->left && !p->right && path.size() > maxDepth) {
: maxDepth = path.size();
: longestPath = path;
d*t
57 楼
1.可以,但是会比较费空间和时间。因为copy constructor要把vector里的节点一个一
个copy到新的里。
2.对
个copy到新的里。
2.对
相关阅读
卡卡的后院累了,追推荐四月妈的猫树请教一下喂猫的朋友们又来奔SusieZZ: 父子偷狗 儿子的弩竟射死老子第一只猫可以理解,第二只就真不理解了 (转载)cat怎么做长距离的relocate啊疯丫头终于闯祸了。。。请问Authority 猫粮能有这样的主人,大概也是宠物的一种幸福吧 (转载)萌图PetSmart's Friend & Family Sale: 15% Off! 9/22求助疑似小T兄弟想要个宠物,请问要不要给猫猫狗狗洗屁股?Captain Kirk发几个wag.com(宠物用品网站)的$10 off code吧妈妈的PDF, FS,>=$59, up to 60lb坚决抵制浙江金华狗肉节