Skip to content

Commit f640d1e

Browse files
authored
Merge pull request #1517 from ivan1016017/january15
January15
2 parents 4e5e12b + e617c54 commit f640d1e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def findMinArrowShots(self, points: List[List[int]]) -> int:
6+
if not points:
7+
return 0
8+
9+
# Sort balloons by end coordinate
10+
points.sort(key=lambda x: x[1])
11+
12+
arrows = 1
13+
current_arrow_pos = points[0][1]
14+
15+
for i in range(1, len(points)):
16+
# If current balloon starts after the last arrow position,
17+
# we need a new arrow
18+
if points[i][0] > current_arrow_pos:
19+
arrows += 1
20+
current_arrow_pos = points[i][1]
21+
22+
return arrows
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function removeElement(nums: number[], val: number): number {
2+
while (nums.includes(val)){
3+
const index = nums.indexOf(val);
4+
nums.splice(index, 1);
5+
}
6+
7+
return nums.length;
8+
9+
};
10+
11+
console.log(removeElement([3,2,2,3], 3))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_22\
3+
.ex_49_min_number_arrows_burst_ballons import Solution
4+
5+
class ArrowsBurstBallonsTestCase(unittest.TestCase):
6+
7+
def test_first_pattern(self):
8+
solution = Solution()
9+
output = solution.findMinArrowShots(points = [[10,16],[2,8],[1,6],[7,12]])
10+
target = 2
11+
self.assertEqual(output, target)
12+
13+
def test_second_pattern(self):
14+
solution = Solution()
15+
output = solution.findMinArrowShots(points = [[1,2],[3,4],[5,6],[7,8]])
16+
target = 4
17+
self.assertEqual(output, target)
18+
19+
def test_third_pattern(self):
20+
solution = Solution()
21+
output = solution.findMinArrowShots(points = [[1,2],[2,3],[3,4],[4,5]])
22+
target = 2
23+
self.assertEqual(output, target)

0 commit comments

Comments
 (0)