降级I-140 nsc 接收一个月后准备追加pp, part4.8 还选no?# EB23 - 劳工卡
b*g
1 楼
我现在想到的就是
1. 先遍历t1 and t2, 找到他们的size,
2. 假设t2比较小,然后就是看t1有无t2
3. 那么我的算法就是
match(Tree t1, Tree t2){
if(t1.value=t2.value)
return match(t1.left,t2.left) && match(t1.right,t2.right);
else
return match(t1.left,t2) || match(t1.right,t2);
}
complexity |t2|*|t1|
有无更好的算法?
1. 先遍历t1 and t2, 找到他们的size,
2. 假设t2比较小,然后就是看t1有无t2
3. 那么我的算法就是
match(Tree t1, Tree t2){
if(t1.value=t2.value)
return match(t1.left,t2.left) && match(t1.right,t2.right);
else
return match(t1.left,t2) || match(t1.right,t2);
}
complexity |t2|*|t1|
有无更好的算法?