문제 설명
https://school.programmers.co.kr/learn/courses/30/lessons/12981

제한 사항

입출력 예


풀이
import java.util.ArrayList;
class Solution {
public int[] solution(int n, String[] words) {
ArrayList<String> wordList = new ArrayList<>();
for (int i = 0; i < words.length; i += n) {
for (int j = i; j < (i + n > words.length ? words.length : i + n); j++) {
if (j != 0)
if (words[j].charAt(0) != words[j - 1].charAt(words[j - 1].length() - 1))
return new int[] { j % n + 1, i / n + 1 };
if (!wordList.contains(words[j])) wordList.add(words[j]);
else return new int[] { j % n + 1, i / n + 1 };
}
}
return new int[] { 0, 0 };
}
}
후기
레벨2 치고는 쉬운 문제였다. 기본으로 주어지는 테스트 예제만 잘 통과시키면 무난하게 통과 할 수 있다.
제출하기 전에 실수해서 코드를 필요 없는 연산을 포함해서 제출해 버렸다... 이러지 않기 위해 조심했는데 더 신경 써야겠다.
'코딩테스트 (프로그래머스) > Java' 카테고리의 다른 글
| [프로그래머스][JAVA][Lv. 1] 자릿수 더하기 (0) | 2023.08.09 |
|---|---|
| [프로그래머스][JAVA][Lv. 1] 자연수 뒤집어 배열로 만들기 (0) | 2023.08.09 |
| [프로그래머스][JAVA][Lv. 1] 정수 내림차순으로 배치하기 (0) | 2023.08.08 |
| [프로그래머스][JAVA][Lv. 1] 정수 제곱근 판별 (0) | 2023.08.07 |
| [프로그래머스][JAVA][Lv. 1] 제일 작은 수 제거하기 (0) | 2023.08.07 |