首页 > 其他分享 >100. 相同的树c

100. 相同的树c

时间:2024-03-05 15:47:15浏览次数:24  
标签:right return struct 相同 val && TreeNode 100

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

结果:

标签:right,return,struct,相同,val,&&,TreeNode,100
From: https://www.cnblogs.com/llllmz/p/18054183

相关文章