Skip to content

Commit

Permalink
[ADD] 添加226_invertTree.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangsir404 committed Mar 8, 2020
1 parent 9966665 commit b3d15ee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
15 changes: 13 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ https://leetcode-cn.com/
### string
- [x] 28. 实现 strStr() 28_strStr.py
- [x] 344. 反转字符串 344_reverseString.py
- [ ] String to Integer (atoi)(字符串转换整数 (atoi))
- [ ] Reverse Words in a String(翻转字符串里的单词)

### sort
- [x] 堆排序算法 heap_sort.py
Expand All @@ -48,13 +50,22 @@ https://leetcode-cn.com/
- [x] 20.有效的括号 20_isValidBraces.py
- [x] 1047. 删除字符串中的所有相邻重复项 1047_removeDuplicates.py
- [x] 224. 基本计算器 224_calculate.py
- [ ] Climbing Stairs(爬楼梯)https://leetcode-cn.com/problems/climbing-stairs/
- [ ] Sliding Window Maximum(滑动窗口最大值) https://leetcode-cn.com/problems/sliding-window-maximum/
- [ ] Design Circular Deque(设计一个双端队列)https://leetcode-cn.com/problems/design-circular-deque/

## queue
- [x] Queue模块的类的实现原理 queue.py

## heap
- [x] 面试题40. 最小的k个数 getLeastNumbers.py

### bitmap
## bitmap
- [x] 位图结构实现 bitmap.py
- [x] 布隆过滤器的实现 bloomfilter.py
- [x] 布隆过滤器的实现 bloomfilter.py

## tree
- [ ] 104. 二叉树的最大深度
- [ ] 111. 二叉树的最小深度
- [x] 226. 翻转二叉树
- [ ] 107. 二叉树的层次遍历 II
22 changes: 22 additions & 0 deletions tree/226_invertTree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
#coding:utf-8

# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None

class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root is None:
return
root.left, root.right = root.right, root.left
self.invertTree(root.left)
self.invertTree(root.right)
return root
9 changes: 9 additions & 0 deletions tree/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python
#coding:utf-8

class TreeNode(object):
"""二叉树节点的定义"""
def __init__(self, x):
self.val = x
self.left = None
self.right = None

0 comments on commit b3d15ee

Please sign in to comment.