aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-05 16:10:51 +0800
committercrupest <crupest@outlook.com>2020-10-05 16:10:51 +0800
commitab991b2b21bc586aa56e37c89c929c1c04d02f97 (patch)
tree4a9214e76c2dacf37801e6a6b7b9af108d8a94bc
parent951ff37ae58fc27d178b1650a8b2af6b01c960f1 (diff)
downloadcrupest-ab991b2b21bc586aa56e37c89c929c1c04d02f97.tar.gz
crupest-ab991b2b21bc586aa56e37c89c929c1c04d02f97.tar.bz2
crupest-ab991b2b21bc586aa56e37c89c929c1c04d02f97.zip
import(solutions): Add problem 100 .
-rw-r--r--works/solutions/cpp/100.cpp29
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);
+ }
+ }
+};