#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
int a=0;
sort(participant.begin(),participant.end(),less<string>());
sort(completion.begin(),completion.end(),less<string>());
for(int i=0;i<participant.size();i++ ){
if(participant[i] != completion[a] ){
answer += participant[i];
}else{
a++;
}
}
return answer;
알고리즘 )
1. participant 정렬함
2. completion 정렬함
=> 순서는 문제푸는데 상관없어보이기 때문에 정렬함
3. 같지않으면 participant를 답에 넣음
=> 같지않으면 completion만 변하도록 함 , 같은 이름일 경우가 존재하므로 completion 만 변하도록 하는것이 깔끔함
'알고리즘' 카테고리의 다른 글
[프로그래머스] level 1 - 시저암호 (0) | 2020.05.16 |
---|---|
[프로그래머스] level 1 - 비밀지도 (0) | 2020.05.08 |
[프로그래머스] level 1 - 크레인 인형뽑기 게임 (0) | 2020.05.04 |
탐욕적 알고리즘 (0) | 2018.12.24 |
완전탐색 (0) | 2018.12.10 |
댓글