프로그래머스 완주하지 못한 선수 C++ 풀이
https://programmers.co.kr/learn/courses/30/lessons/42576
// participant 배열이 completion 배열보다 길이가 1 길다.
// participant 배열과 completion 배열을 일단 sort 하고
// 이름이 모두 다르니까 participant 배열과 completion 배열의 사람의 위치 (인덱스) 가 다르면 return
// 만약 위에서 return이 안됬으면 sort한 participant 배열의 마지막 사람이 답 retrun
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
sort(participant.begin(), participant.end());
sort(completion.begin(), completion.end());
for (int i = 0; i < participant.size(); i++){
if (participant[i] != completion[i])
return participant[i];
}
return participant[participant.size()-1];
}
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 다리를 지나는 트럭 (0) | 2023.07.07 |
---|---|
[프로그래머스] 탑 (0) | 2023.07.07 |
[프로그래머스] 베스트앨범 (0) | 2023.07.07 |
[프로그래머스] 위장 (0) | 2023.07.06 |
[프로그래머스] 전화번호 목록 (0) | 2023.07.06 |