We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a9b5844 commit 3d850f8Copy full SHA for 3d850f8
solution/0100-0199/0101.Symmetric Tree/Solution.cpp
@@ -0,0 +1,14 @@
1
+class Solution {
2
+public:
3
+ bool isSymmetric(TreeNode* root) {
4
+ if (!root) return true;
5
+ return isSymmetric(root->left, root->right);
6
+ }
7
+
8
+private:
9
+ bool isSymmetric(TreeNode* left, TreeNode* right) {
10
+ if (!left && !right) return true;
11
+ if (!left && right || left && !right || left->val != right->val) return false;
12
+ return isSymmetric(left->left, right->right) && isSymmetric(left->right, right->left);
13
14
+};
0 commit comments