Skip to content

Commit 0b8c2d7

Browse files
committed
452
1 parent 71f6e9e commit 0b8c2d7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ Success is like pregnancy, Everybody congratulates you but nobody knows how many
102102
|40|[Combination Sum II](https://leetcode.com/problems/combination-sum-ii/#/solutions)| [Python [Yu]](./backtrack/Yu/39.py) | _O(K * (2^N)_| _O(N)_ | Medium | |[公瑾讲解](https://youtu.be/HdS5dOaz-mk)|
103103
|216|[Combination Sum III](https://leetcode.com/problems/combination-sum-iii/#/description)| [Python [Yu]](./backtrack/Yu/216.py) | _O(K * (2^N)_| _O(N)_ | Medium | ||
104104

105+
## Greedy Medium
106+
| # | Title | Solution | Time | Space | Difficulty | Note|
107+
|-----|-------| -------- | ---- | ------|------------|-----|
108+
|452|[Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/#/description)| [Python [Yu]](./greedy/452.py) | _O(N)_| _O(1)_ | Medium| |
105109

106110
## Dynamic Programming Easy
107111
| # | Title | Solution | Time | Space | Difficulty | Note|

greedy/452.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# Author: Yu Zhou
5+
# 452. Minimum Number of Arrows to Burst Balloons
6+
7+
# 用到了Greedy的一个,扫描线的运用
8+
# 先进行排序,然后在每次循环的时候
9+
# 比对end point,然后更新end point,若超出end point范围,则增加一个arrow
10+
# 这道题的知识点是扫描线+ 如何sort 一个tuple里面的第一个值
11+
12+
class Solution(object):
13+
def findMinArrowShots(self, points):
14+
"""
15+
:type points: List[List[int]]
16+
:rtype: int
17+
"""
18+
19+
points = sorted(points, key = lambda x: x[1])
20+
end = -float('inf')
21+
res = 0
22+
for ballon in points:
23+
if ballon[0] > end:
24+
end = ballon[1]
25+
res += 1
26+
return res

0 commit comments

Comments
 (0)