[Programmers] 단속카메라

Time Lapse :NONE

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <vector>
#include <algorithm>
//6:39
using namespace std;
bool mysort(vector<int> v1, vector<int> v2){
if(v1[1]<v2[1])
return true;
if(v1[1]==v2[1])
return v1[0]<v2[0];
return false;
}
int solution(vector<vector<int>> routes) {
int answer = 1;
sort(routes.begin(),routes.end(),mysort);
int pos = routes[0][1];
for(int i=0;i<routes.size();i++){
if(pos<routes[i][0]) {
pos = routes[i][1];
answer++;
}
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/IntermittentCamera/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.