leetcode-100-树题-相同的树 发表于 2020-03-19 | 分类于 数据结构与算法 题目 解法123456789101112131415161718/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: bool isSameTree(TreeNode* p, TreeNode* q) { if(!p && !q) return true; if((p && !q) || (!p && q) || p->val != q->val) return false; return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); }};