반응형
다른분들과 풀이가 같다.
#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
vector<int> solution(int n, vector<string> words) {
map<string, int> m;
int size = words.size();
for(int i = 0; i < words.size(); i++) {
if(m[words[i]]++ > 0 || (i > 0 && words[i][0] != words[i - 1][words[i - 1].length() - 1])) {
return {i % n + 1, i / n + 1};
}
}
return {0, 0};
}
종료조건은
1. 이미 등장한 단어이거나
2. 이전 단어와 끝말잇기가 아닐경우
두가지 중 하나에 만족하면 된다.
반응형
'[알고리즘 + 자료구조] > [프로그래머스]' 카테고리의 다른 글
프로그래머스 땅따먹기 (0) | 2023.08.09 |
---|---|
프로그래머스 예상 대진표 (0) | 2023.08.09 |
프로그래머스 H-index (0) | 2023.08.08 |
프로그래머스 타겟 넘버 (0) | 2023.08.08 |
프로그래머스 카펫 (0) | 2023.08.07 |