小程序 - leetcode 100. Same Tree

Posted brayden

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小程序 - leetcode 100. Same Tree相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/same-tree/

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

 

以上是关于小程序 - leetcode 100. Same Tree的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode[100]-Same Tree

[LeetCode]题解(python):100 Same Tree

LeetCode(100):Same Tree

leetcode-- 100. Same Tree

LeetCode笔记:100. Same Tree

Leetcode-100 Same Tree