设为首页 加入收藏

TOP

LeeCode 判断两个二叉树是否相等
2015-11-21 01:01:45 来源: 作者: 【 】 浏览:1
Tags:LeeCode 判断 两个二 是否 相等

?

题目:

?

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.

C代码:

?

/**
 * 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 true;
     else if(p==NULL || q==NULL) return false;
     else return p->val==q->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
        
}


?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c++ 中的空指针和void指针 下一篇C/C++ 生成文件夹 删除文件夹 获..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: