| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 43. Multiply Strings
- LeetCode
- iterator
- Python
- Generator
- DWG
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- data science
- kaggle
- Python Code
- t1
- 30. Substring with Concatenation of All Words
- Protocol
- 파이썬
- Substring with Concatenation of All Words
- Regular Expression
- 밴픽
- Python Implementation
- Decorator
- 109. Convert Sorted List to Binary Search Tree
- concurrency
- 컴퓨터의 구조
- 운영체제
- attribute
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- Class
- 시바견
- shiba
Archives
- Today
- Total
Scribbling
[C++] vector<vector<int>> sorting with comparator 본문
LeetCode: 452. Minimum Number of Arrows to Burst Balloons
Minimum Number of Arrows to Burst Balloons - LeetCode
Can you solve this real interview question? Minimum Number of Arrows to Burst Balloons - There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xst
leetcode.com
class Solution {
public:
int findMinArrowShots(vector<vector<int>>& points) {
// using lambda comparator function
sort(points.begin(), points.end(), [](const vector<int>& vec1, const vector<int>& vec2){
return vec1[1] < vec2[1];
});
int ret = 1;
int shot = points[0][1];
for (int i=1; i<points.size(); i++) {
if (points[i][0] <= shot) {
continue;
} else {
shot = points[i][1];
ret++;
}
}
return ret;
}
};
class Solution {
public:
static bool cmp(vector<int>& a, vector<int>& b) { return a[1] < b[1]; }
int findMinArrowShots(vector<vector<int>>& points) {
sort(points.begin(), points.end(), cmp);
int ret = 1;
int end = points[0][1];
for (int i = 1; i < points.size(); i++) {
if (points[i][0] <= end) {
continue;
}
ret++;
end = points[i][1];
}
return ret;
}
};'Computer Science > C++' 카테고리의 다른 글
| [C++] 2d DP table with vector (0) | 2023.09.19 |
|---|---|
| [C++] 전문가를 위한 C++ - Chapter 1 (0) | 2023.09.15 |
| [C++] priority queue (pair<int, pair<int, int>>), minheap (0) | 2023.09.02 |
| [C++] vector sum, dp table with vector (0) | 2023.09.02 |
| [C++] unordered_map, unordered_set, substr (0) | 2023.08.31 |