檢查兩個二叉樹是否相同
- 例如,如果輸入是:
實施例:1
一個)
b)
輸出應該是真的。
例如:2
如果輸入是:
一個)
b)
輸出應該是假的。
虛擬碼相同:
boolean sameTree(node root1, node root2){
if(root1 == NULL && root2 == NULL)
return true;
if(root1 == NULL || root2 == NULL)
return false;
if(root1->data == root2->data
&& sameTree(root1->left,root2->left)
&& sameTree(root1->right, root2->right))
return true;
}