일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 시바견
- 컴퓨터의 구조
- 715. Range Module
- 밴픽
- kaggle
- 운영체제
- 43. Multiply Strings
- attribute
- LeetCode
- Python Implementation
- Python
- Regular Expression
- Substring with Concatenation of All Words
- shiba
- concurrency
- Decorator
- iterator
- Python Code
- 파이썬
- Generator
- DWG
- data science
- 315. Count of Smaller Numbers After Self
- Class
- 109. Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- t1
- Protocol
- 프로그래머스
- Convert Sorted List to Binary Search Tree
Archives
- Today
- Total
Scribbling
[C++] vector<vector<int>> sorting with comparator 본문
LeetCode: 452. Minimum Number of Arrows to Burst Balloons
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 |