programmers_영어 끝말잇기_java
2023. 3. 22. 23:32ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/12981
import java.util.*;
class Solution {
public int[] solution(int n, String[] words) {
int[] answer = {0,0};
Set<String> set = new HashSet<String>();
int wordsSize = words.length;
int num = 0;
int turn = 1;
for(int i = 0; i<wordsSize; i++){
if(set.contains(words[i])){
answer[0] = num%n +1;
answer[1] = turn;
return answer;
}
if(i > 0){
if(words[i-1].charAt(words[i-1].length() -1) != words[i].charAt(0)){
answer[0] = num%n +1;
answer[1] = turn;
return answer;
}
}
set.add(words[i]);
num++;
if(num%n == 0) turn++;
}
return answer;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_미로 탈출_java (0) | 2023.03.28 |
---|---|
programmers_광물 캐기_java (0) | 2023.03.23 |
programmers_[1차] 셔틀버스_java (0) | 2023.03.17 |
programmers_가장 긴 팰린드롬_java (0) | 2023.03.14 |
programmers_입국심사_java (0) | 2023.03.13 |