Skip to content

Commit 4f3c026

Browse files
committed
Leetcode 101
python
1 parent 14e5070 commit 4f3c026

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Personal Practice Set - Doing One a Day (sometimes) in a Variety of Languages (M
5757
| 70 | Easy | [Climbing Stairs](leetcode/70-Easy-Climbing-Stairs/problem.md) | [C](leetcode/70-Easy-Climbing-Stairs/answer.c) |
5858
| 83 | Easy | [Remove Duplicates from Sorted List](leetcode/83-Easy-Remove-Duplicates-From-Sorted-List/problem.md) | [Python](leetcode/83-Easy-Remove-Duplicates-From-Sorted-List/answer.py)|
5959
| 100| Easy | [Same Tree](leetcode/100-Easy-Same-Tree/problem.md) | [Python](leetcode/100-Easy-Same-Tree/answer.py) |
60+
| 101| Easy | [Symmetric Tree](leetcode/101-Easy-Symmetric-Tree/problem.md) | [Python](leetcode/101-Easy-Symmetric-Tree/answer.py) |
6061
| 104| Easy | [Maximum Depth of Binary Tree](leetcode/104-Easy-Maximum-Depth-Of-Binary-Tree/problem.md) | [Python](leetcode/104-Easy-Maximum-Depth-Of-Binary-Tree/answer.py)|
6162
| 105| Medium | [Construct Binary Tree from Preorder and Inorder Traversal](leetcode/105-Medium-Construct-Binary-Tree-From-Preorder-And-Inorder-Traversal/problem.md) | [Python](leetcode/105-Medium-Construct-Binary-Tree-From-Preorder-And-Inorder-Traversal/answer.py)|
6263
| 106| Medium | [Construct Binary Tree from Inorder and Postorder Traversal](leetcode/106-Medium-Construct-Binary-Tree-From-Inorder-And-Postorder-Traversal/problem.md) | [Python](leetcode/106-Medium-Construct-Binary-Tree-From-Inorder-And-Postorder-Traversal/answer.py)|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
#-------------------------------------------------------------------------------
4+
# Definition for a binary tree node.
5+
# class TreeNode:
6+
# def __init__(self, x):
7+
# self.val = x
8+
# self.left = None
9+
# self.right = None
10+
11+
class Solution:
12+
def isSymmetric(self, root):
13+
"""
14+
:type root: TreeNode
15+
:rtype: bool
16+
"""
17+
return self.isEqual(root, root)
18+
19+
def isEqual(self, n1, n2):
20+
if not n1 and not n2: return True
21+
if not n1 or not n2: return False
22+
return (n1.val == n2.val) and self.isEqual(n1.right, n2.left) and self.isEqual(n1.left, n2.right)
23+
24+
#-------------------------------------------------------------------------------
25+
# Testing
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Problem 101: Symmetric Tree
2+
3+
4+
#### Difficulty: Easy
5+
6+
#### Problem
7+
8+
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
9+
10+
#### Example
11+
12+
<pre>
13+
14+
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
15+
16+
1
17+
/ \
18+
2 2
19+
/ \ / \
20+
3 4 4 3
21+
</pre>

0 commit comments

Comments
 (0)