https://school.programmers.co.kr/learn/courses/30/lessons/12981
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
vector<int> solution(int n, vector<string> words) {
set<string> s;
int cnt{ 0 };
auto res = any_of(words.begin(), words.end(), [&](const auto& str)
{
const auto& lastWord = cnt ? words[cnt - 1].back() : words[0].front();
if (s.find(str) != s.end() || lastWord != str.front())
return true;
s.insert(str), ++cnt;
return false;
});
return res ? vector<int>{ cnt % n + 1, cnt / n + 1 } : vector<int>{ 0, 0 };
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (탐욕법(Greedy)) Lv 2. 구명보트 (0) | 2023.05.30 |
---|---|
[Programmers] (완전탐색) Lv 2. 카펫 (0) | 2023.05.25 |
[Programmers] (2017 팁스타운) Lv 2. 짝지어 제거하기 (0) | 2023.05.23 |
[Programmers] Lv 2. 피보나치 수 (0) | 2023.05.22 |
[Programmers] Lv 2. 다음 큰 숫자 (0) | 2023.05.19 |
댓글