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 | ab991b2b21bc586aa56e37c89c929c1c04d02f97 (patch) | |
tree | 4a9214e76c2dacf37801e6a6b7b9af108d8a94bc | |
parent | 951ff37ae58fc27d178b1650a8b2af6b01c960f1 (diff) | |
download | crupest-ab991b2b21bc586aa56e37c89c929c1c04d02f97.tar.gz crupest-ab991b2b21bc586aa56e37c89c929c1c04d02f97.tar.bz2 crupest-ab991b2b21bc586aa56e37c89c929c1c04d02f97.zip |
import(solutions): Add problem 100 .
-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);
+ }
+ }
+};
|