강의로 돌아가기

### 테스트 19번만 실패라고 뜨네요..

class Solution {
public int[] solution(int n, String[] words) {
if(n >= 2 && n <= 10 && words.length >= n && words.length <= 100) {
a: for(int i = 0; i < words.length - 1; i++) {
if(!words[i].substring(words[i].length()-1,words[i].length()).equals(words[i+1].substring(0,1))) {
answer[0] = (i+1) % n + 1;
answer[1] = (i+1) / n + 1;
break;
}else if(words[i].length() <= 1) {
answer[0] = (i) % n + 1;
answer[1] = (i) / n + 1;
}else {
for(int j = i+1; j < words.length; j++) {
if(words[i].equals(words[j])) {
answer[0] = j % n + 1;
answer[1] = j / n + 1;
break a;
}
}
}
}
}
}
}
제 코드 이고요.. 어디서 문제가 생긴 건지 알 수가 없어서 ㅠㅠ.. 문제가 있으면 알려주세요 ...

##### 1 개의 답변

class Solution {
public int[] solution(int n, String[] words) {
if(n >= 2 && n <= 10 && words.length >= n && words.length <= 100) {
a: for(int i = 1; i < words.length; i++) {
if(!words[i-1].substring(words[i-1].length()-1,words[i-1].length()).equals(words[i].substring(0,1))) {
answer[0] = (i) % n + 1;
answer[1] = (i) / n + 1;
break;
}else if(words[i].length() <= 1) {
answer[0] = (i) % n + 1;
answer[1] = (i) / n + 1;
}else {
for(int j = 0; j < i; j++) {
if(words[i].equals(words[j])) {
answer[0] = i % n + 1;
answer[1] = i / n + 1;
break a;
}
}
}
}
}
}
}