diff options
| author | crupest <crupest@outlook.com> | 2020-10-05 16:10:51 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2020-10-05 16:10:51 +0800 | 
| commit | 5996544acb4b8e205868bcc26c98b401a8f8c2a6 (patch) | |
| tree | 88514c7febd832b315cf340d936cbf561671951b /works/solutions | |
| parent | b08eced5352c9118b539b8a4e6dc1bd1f4c7f371 (diff) | |
| download | crupest-5996544acb4b8e205868bcc26c98b401a8f8c2a6.tar.gz crupest-5996544acb4b8e205868bcc26c98b401a8f8c2a6.tar.bz2 crupest-5996544acb4b8e205868bcc26c98b401a8f8c2a6.zip | |
import(solutions): Add problem 100 .
Diffstat (limited to 'works/solutions')
| -rw-r--r-- | works/solutions/cpp/100.cpp | 29 | 
1 files changed, 29 insertions, 0 deletions
| diff --git a/works/solutions/cpp/100.cpp b/works/solutions/cpp/100.cpp new file mode 100644 index 0000000..28448d1 --- /dev/null +++ b/works/solutions/cpp/100.cpp @@ -0,0 +1,29 @@ +struct TreeNode
 +{
 +    int val;
 +    TreeNode *left;
 +    TreeNode *right;
 +    TreeNode() : val(0), left(nullptr), right(nullptr) {}
 +    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 +    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 +};
 +
 +class Solution
 +{
 +public:
 +    bool isSameTree(TreeNode *p, TreeNode *q)
 +    {
 +        if (p == nullptr)
 +        {
 +            if (q == nullptr)
 +                return true;
 +            return false;
 +        }
 +        else
 +        {
 +            if (q == nullptr)
 +                return false;
 +            return p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
 +        }
 +    }
 +};
 | 
