Skip to content

Commit 175acfc

Browse files
authored
Merge pull request gzc426#295 from wswdwf/patch-12
Create Sagittarius.md
2 parents ee79193 + dc858ab commit 175acfc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

2018.12.4-leetcode101/Sagittarius.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```
2+
/**
3+
* Definition for a binary tree node.
4+
* struct TreeNode {
5+
* int val;
6+
* TreeNode *left;
7+
* TreeNode *right;
8+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9+
* };
10+
*/
11+
bool isSymmetric1(TreeNode* r1,TreeNode* r2)
12+
{
13+
if(!r1&&!r2)
14+
return true;
15+
else if((r1&&!r2)||(!r1&&r2))
16+
return false;
17+
else
18+
{
19+
if(r1->val!=r2->val)
20+
return false;
21+
else
22+
return isSymmetric1(r1->left,r2->right)&&isSymmetric1(r1->right,r2->left);
23+
}
24+
25+
}
26+
class Solution {
27+
public:
28+
bool isSymmetric(TreeNode* root) {
29+
if(!root)
30+
return true;
31+
else
32+
return isSymmetric1(root->left,root->right);
33+
}
34+
};
35+
```

0 commit comments

Comments
 (0)