public int[] solution(int n, String[] words) {
HashSet<String> set = new HashSet<>();
set.add(words[0]);
for (int i = 1; i < words.length; i++) {
String previousWord = words[i - 1];
String currentWord = words[i];
char last = previousWord.charAt(previousWord.length() - 1);
char first = currentWord.charAt(0);
if (set.contains(currentWord) || last != first) {
int setNum = set.size();
return new int[] { setNum % n + 1, setNum / n + 1 };
}
set.add(currentWord);
}
return new int[] { 0, 0 };
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12981