add: 0100 (2)

This commit is contained in:
Lam Haoyin 2022-02-03 21:40:11 +08:00
parent 9e7354fc5c
commit 8c4da77b8f
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
1 changed files with 13 additions and 2 deletions

View File

@ -8,9 +8,20 @@ struct TreeNode {
explicit TreeNode(int x = 0, TreeNode* left = nullptr, TreeNode* right = nullptr) : val(x), left(left), right(right) {} explicit TreeNode(int x = 0, TreeNode* left = nullptr, TreeNode* right = nullptr) : val(x), left(left), right(right) {}
}; };
/**
* 100. Same Tree
* Given the roots of two binary trees p and q, write a function to check if they are the same or not.
* Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
*/
class Solution { class Solution {
public: public:
static bool isSameTree(TreeNode* p, TreeNode* q) { static bool isSameTree(const TreeNode* const p, const TreeNode* const q) {
return (p == q) || (p && q && p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right)); return (p == q) || (p && q && p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right));
} }
}; };
int main() {
// No code for testing
return 0;
}