add: 0100 (2)
This commit is contained in:
parent
9e7354fc5c
commit
8c4da77b8f
|
|
@ -8,9 +8,20 @@ struct TreeNode {
|
|||
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 {
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
// No code for testing
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue