Problem Solving/Programmers
[Level 2] 영어 끝말잇기
kmkunk
2022. 4. 6. 12:53
import java.util.*;
class Solution {
public int[] solution(int n, String[] words) {
int[] answer = new int[2];
List<String> list = new ArrayList<>();
list.add(words[0]);
for(int i=1; i<words.length; i++) {
String w1 = words[i-1];
String w2 = words[i];
if(w1.charAt(w1.length()-1)!=w2.charAt(0) || list.contains(w2)) {
answer[0] = i%n+1;
answer[1] = i/n+1;
break;
}
list.add(w2);
}
return answer;
}
}