-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
35 lines (29 loc) · 1.15 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package question;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Solution solution = new Solution();
solution.solution(5, new String[] {"hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"});
}
public static class Solution {
public int[] solution(int n, String[] words) {
int[] answer = new int[2];
Set<String> set = new HashSet<>();
set.add(words[0]);
for(int i=1; i<words.length; i++){
if(words[i - 1].charAt(words[i - 1].length()-1) != words[i].charAt(0) || set.contains(words[i])){
answer[0] = i % n + 1;
answer[1] = i / n + 1;
break;
}
else
set.add(words[i]);
}
return answer;
}
}
}