728x90
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/120869
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
중복된 문자가 있으면 지우고 없으면 추가하여 나온 vector를 순회하여 string값이 empty면 answer를 1로 세팅하여 return한다.
#include <string>
#include <vector>
using namespace std;
int solution(vector<string> spell, vector<string> dic) {
int answer = 2;
for (int i = 0; i < dic.size(); i++)
{
for (int j = 0; j < spell.size(); j++)
{
auto iter = dic[i].find(spell[j]);
if (iter != string::npos)
{
//exist
dic[i].erase(iter, 1);
}
else {
dic[i].append(spell[j]);
}
}
}
for (int i = 0; i < dic.size(); i++)
{
if (dic[i].empty())
{
answer = 1;
break;
}
}
return answer;
}
728x90
반응형
'개발일지 > 코딩테스트' 카테고리의 다른 글
[Programmers] 약수의 개수와 덧셈(C++) (0) | 2025.04.03 |
---|---|
[Programmers] 옹알이(1) (c++) (0) | 2025.04.02 |
[Programmers] 합성 수 찾기 (c++) (0) | 2025.03.31 |
[Programmers] 가장 큰 수(c++) (0) | 2025.03.31 |
[Programmers] 약수의 합(c++) (0) | 2025.03.28 |