Skip to content

Commit 3989da4

Browse files
committed
update readme
1 parent b181dab commit 3989da4

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

Algorithm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
1. [约瑟夫环](https://github.com/lambdaplus/python/blob/master/Algorithm/joseph-ring.py)
22
2. [寻找两个链表的第一个交点](https://www.zybuluo.com/Scrazy/note/719335)
3+
3. [删除链表中的重复元素](https://www.zybuluo.com/Scrazy/note/720542)
4+
4. [数组中的数组成最小值](https://www.zybuluo.com/Scrazy/note/720582)
5+
5. [索引为index 的丑数](https://www.zybuluo.com/Scrazy/note/720587)

binary_tree.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,19 @@ s = Solution()
273273
t = s.reConstructBinaryTree(pre, tin)
274274
s.print_tree(t)
275275
```
276-
树的子结构
276+
### 树的子结构
277277

278278
```python
279+
求pRoot2 的子树是否为 pRoot2
279280
# -*- coding:utf-8 -*-
280281
# class TreeNode:
281282
# def __init__(self, x):
282283
# self.val = x
283284
# self.left = None
284285
# self.right = None
285286
class Solution:
286-
def is_subtree(self, t1, t2):
287-
if not t2:
287+
def is_subtree(self, t1, t2):
288+
if not t2: # t2 is None 其为子树
288289
return True
289290
if not t1:
290291
return False
@@ -304,4 +305,26 @@ class Solution:
304305
result = self.is_subtree(pRoot1.right, pRoot2)
305306
return result
306307
```
308+
### 对称二叉树
307309

310+
```
311+
# -*- coding:utf-8 -*-
312+
# class TreeNode:
313+
# def __init__(self, x):
314+
# self.val = x
315+
# self.left = None
316+
# self.right = None
317+
class Solution:
318+
319+
def isSymmetrical(self, pRoot):
320+
def is_same(p1, p2):
321+
if not (p1 or p2):
322+
return True
323+
elif p1 and p2 and p1.val == p2.val:
324+
return is_same(p1.left, p2.right) and is_same(p1.right, p2.left)
325+
return False
326+
327+
if not pRoot:
328+
return True
329+
return is_same(pRoot.left, pRoot.right)
330+
```

0 commit comments

Comments
 (0)