알고리즘/그리디
[C++] 프로그래머스 : 단속 카메라
mezo
2021. 2. 2. 00:31
728x90
반응형
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<vector<int>> routes) {
int answer = 1;
sort(routes.begin(), routes.end());
int tmp = routes[0][1];
for(int i = 0; i<routes.size()-1; i++){
if(tmp > routes[i][1]) tmp = routes[i][1];
if(tmp < routes[i+1][0]){
answer++;
tmp = routes[i+1][1];
}
}
return answer;
}
728x90
반응형