Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 35ce63e

Browse files
committed
[20230105] Solve medium problem
1 parent dcb8a96 commit 35ce63e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 452. Minimum Number of Arrows to Burst Balloons
2+
# https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/
3+
4+
from typing import List
5+
6+
7+
class Solution:
8+
def findMinArrowShots(self, points: List[List[int]]) -> int:
9+
# point ๊ฐ’์ด ์ตœ์†Œ 1๊ฐœ ์ด์ƒ ์žˆ์–ด์„œ
10+
# ๋ฌด์กฐ๊ฑด ํ•œ๊ฐœ์˜ ํ™”์‚ด์„ ์˜๊ฒŒ ๋˜์–ด ์žˆ์Œ
11+
result = 1
12+
13+
# ํ’์„ ์˜ ๋์ ์œผ๋กœ ์ •๋ ฌํ•จ
14+
points.sort(key=lambda x: x[1])
15+
prev = points[0]
16+
for point in points:
17+
# ํ’์„ ์ด ์„œ๋กœ ์•ˆ ๋‹ฟ์•„ ์žˆ์Œ
18+
# ๊ทธ๋Ÿฌ๋ฉด ๋‹ค์Œ ํ’์„ ์„ burst ํ•˜๊ธฐ ์œ„ํ•ด ํ™”์‚ด์„ ์œ๋‹ค
19+
if prev[1] < point[0]:
20+
result += 1
21+
prev = point
22+
# else ๋ผ๋ฉด ๋‹ฟ์•„ ์žˆ๋‹ค๋Š” ์˜๋ฏธ ์ด๋ฏ€๋กœ
23+
# ํ™”์‚ด์„ ์  ํ•„์š”๊ฐ€ ์—†๋‹ค. (์ด๋ฏธ prev ํ’์„  ํ™•์ธ ํ•˜๋ฉด์„œ ์ˆ๊ธฐ ๋•Œ๋ฌธ์ž„)
24+
25+
return result
26+
27+
28+
if __name__ == '__main__':
29+
sol = Solution()
30+
print(sol.findMinArrowShots([[10, 16], [2, 8], [1, 6], [7, 12]]))

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /