标签:
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
[Solution]
递归判断val是否相等.
1 bool isSameTree(TreeNode *p, TreeNode *q) 2 { 3 if (p == NULL || q == NULL) 4 { 5 if (p == q) 6 return true; 7 else 8 return false; 9 } 10 else 11 { 12 if (p->val == q->val) 13 return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); 14 else 15 return false; 16 } 17 }
标签:
原文地址:http://www.cnblogs.com/ym65536/p/4295351.html