Skip to content

Commit 2260a3f

Browse files
authored
[20251017] PGM / Lv2 / 영어 끝말잇기 / 이강현
1 parent c0675dc commit 2260a3f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int[] solution(int n, String[] words) {
5+
6+
Map<String,Boolean> history = new HashMap<>();
7+
8+
int fail = 0;
9+
String prev = words[0];
10+
history.put(prev,true);
11+
for(int i=1;i<words.length;i++){
12+
if(prev.charAt(prev.length()-1) == words[i].charAt(0)
13+
&& history.get(words[i]) == null
14+
&& words.length>1){
15+
prev = words[i];
16+
history.put(words[i],true);
17+
}else{
18+
fail = i;
19+
break;
20+
}
21+
}
22+
if(fail == 0){
23+
return new int[]{0,0};
24+
}
25+
return new int[]{(fail%n)+1,(fail/n)+1};
26+
}
27+
}
28+
```

0 commit comments

Comments
 (0)