programmers_스킬트리_java
2023. 4. 10. 18:31ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/49993#
import java.util.*;
class Solution {
public int solution(String skill, String[] skill_trees) {
int answer = 0;
// 스킬 트리 순서 dict
Map<Character, Integer> dict = new HashMap<>();
int skillLength = skill.length();
for(int i = 0; i<skillLength; i++){
dict.put(skill.charAt(i), i);
}
// 스킬 트리 확인
int skill_treesLength = skill_trees.length;
for(int i = 0; i<skill_treesLength; i++){
int before = -1; // 스킬트리는 0부터 시작
int skillTreeLength = skill_trees[i].length();
boolean isSuc = true;
for(int j = 0; j<skillTreeLength; j++){
char now = skill_trees[i].charAt(j); // 현재 스킬
if(dict.containsKey(now)){
if(dict.get(now) == before+1){
before = dict.get(now);
}else if(dict.get(now) > before){
isSuc = false;
break;
}
}
}
if(isSuc){
answer++;
}
}
return answer;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_모음 사전_java (0) | 2023.04.11 |
---|---|
programmers_방문 길이_java (0) | 2023.04.11 |
programmers_땅따먹기_java (0) | 2023.04.10 |
programmers_주차 요금 계산_java (0) | 2023.04.10 |
programmers_[3차] n진수 게임_java (0) | 2023.04.10 |