컴퓨터공학/알고리즘 문제풀이
[프로그래머스 C++] 단속카메라
Pyxis
2024. 10. 31. 15:38
[프로그래머스 C++ : 단속카메라]
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<vector<int>> routes) {
int answer = 0;
::sort(routes.begin(), routes.end(), [](const vector<int>& A, const vector<int>& B) { return A[1] < B[1]; });
// [-20, -15], [-18, -13], [-14, -5], [-5, -3]
int cnt = 0;
int last = -30'001;
for (int i=0; i<routes.size(); i++)
{
const int start = routes[i][0];
const int end = routes[i][1];
if (last < start)
{
cnt++;
last = end;
}
}
return answer = cnt;
}