# ★☆☆☆☆ 영어 끝말잇기

# 구현코드

package pgm_12981;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public int[] solution(int n, String[] words) {
        Set<String> sayLog = new HashSet<>();
        int cnt = 1;
        int person = 0;
        String prevWord = String.valueOf(words[0].charAt(0));
        for(String word : words){
            if(sayLog.contains(word) || prevWord.charAt(prevWord.length()-1) != word.charAt(0))
                return new int[]{person+1,cnt};
            prevWord = word;
            sayLog.add(word);
            if(person % n == n-1)
                cnt++;
            person = (person + 1)%n;
        }
        return new int[]{0,0};
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23