Skip to content

Commit 5c2bdfd

Browse files
authored
Create GatesMa.md
1 parent e7c6761 commit 5c2bdfd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

2018.12.4-leetcode101/GatesMa.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# c++
2+
```cpp
3+
/**
4+
* Definition for a binary tree node.
5+
* struct TreeNode {
6+
* int val;
7+
* TreeNode *left;
8+
* TreeNode *right;
9+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
bool isSymmetric(TreeNode* root) {
15+
return isMirror(root, root);
16+
}
17+
bool isMirror(TreeNode *t1, TreeNode *t2){
18+
if(t1 == NULL && t2 == NULL) return true;
19+
if(t1 == NULL || t2 == NULL) return false;
20+
return (t1->val == t2->val) && isMirror(t1->left, t2->right) && isMirror(t1->right, t2->left);
21+
}
22+
};
23+
```

0 commit comments

Comments
 (0)