Xiaohe-LeetCode 100 Same Tree

Best Solution 0ms

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {

  if (p==NULL&&q==NULL)
    return 1;
  else if ((!p&&q)||(p&&!q))
    return 0;
  return (isSameTree(p->left,q->left)&&isSameTree(p->right,q->right))&&(p->val==q->val);

}

posted @ 2015-11-22 10:35  CathyXiaohe  阅读(150)  评论(0编辑  收藏  举报