원본 : https://school.programmers.co.kr/learn/courses/30/lessons/12981
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
import java.util.*;
class Solution {
public int[] solution(int n, String[] words) {
LinkedList<String> list = new LinkedList<>();
for (int i = 0; i < words.length; i += n) {
for (int j = 0; j < n; j++) {
String str = words[i + j];
if (list.size() > 0) {
String preStr = list.peekLast();
if (preStr.charAt(preStr.length() - 1) != str.charAt(0)) {
return new int[]{j + 1, i / n + 1};
}
}
if (list.contains(str)) {
return new int[]{j + 1, i / n + 1};
}
list.add(str);
}
}
return new int[]{0, 0};
}
}
예상 대진표 (2017 팁스타운) (0) | 2022.07.07 |
---|---|
게임 맵 최단거리 (찾아라 프로그래밍 마에스터) (0) | 2022.07.07 |
소수 찾기 (완전탐색) (0) | 2022.07.05 |
가장 큰 수 (정렬) (0) | 2022.07.05 |
프린터 (스택/큐) (0) | 2022.07.05 |
댓글 영역