From dc1f0c4c0096013799416664894c5194dc7e1f52 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- store/works/solutions/leetcode/cpp/101.cpp | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 store/works/solutions/leetcode/cpp/101.cpp (limited to 'store/works/solutions/leetcode/cpp/101.cpp') diff --git a/store/works/solutions/leetcode/cpp/101.cpp b/store/works/solutions/leetcode/cpp/101.cpp new file mode 100644 index 0000000..a1dad6f --- /dev/null +++ b/store/works/solutions/leetcode/cpp/101.cpp @@ -0,0 +1,43 @@ +#include + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + static bool check(TreeNode *left, TreeNode *right) + { + if (left == NULL) + { + if (right == NULL) + return true; + else + return false; + } + else + { + if (right == NULL) + return false; + else + { + if (left->val != right->val) + return false; + return check(left->left, right->right) && check(left->right, right->left); + } + } + } + + bool isSymmetric(TreeNode *root) + { + if (root == nullptr) + return true; + + return check(root->left, root->right); + } +}; -- cgit v1.2.3