Skip to content

Commit 3d850f8

Browse files
committed
feat:add Solution.cpp for 0101.Symmetric Tree
1 parent a9b5844 commit 3d850f8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)