https://school.programmers.co.kr/learn/courses/30/lessons/160586
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
private static final int NOT_FOUND = 102;
public int[] solution(String[] keymap, String[] targets) {
int size = targets.length;
int[] answer = new int[size];
for(int i = 0 ; i < size ; i++){
String target = targets[i];
int result = 0;
for(int j = 0 ; j < target.length() ; j++){
int index = NOT_FOUND;
for(String str : keymap){
int tempIndex = str.indexOf(target.charAt(j));
if(tempIndex == -1){
continue;
}
index = Math.min(index,tempIndex+1);
}
if(index == NOT_FOUND){
result = -1;
break;
}
result += index;
}
answer[i] = result;
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 미로 탈출 (JAVA) (0) | 2023.04.13 |
---|---|
프로그래머스 시소 짝궁 (JAVA) (0) | 2023.04.12 |
프로그래머스 풍선 터트리기 (JAVA) (0) | 2023.04.10 |
프로그래머스 가장 긴 팰린드룸(JAVA) (0) | 2023.04.10 |
프로그래머스 마법의 엘리베이터(JAVA) (0) | 2023.04.08 |