-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDH_49993.java
More file actions
40 lines (31 loc) · 1.08 KB
/
DH_49993.java
File metadata and controls
40 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.*;
/*
스킬트리
*/
public class DH_49993 {
public int solution(String skill, String[] skill_trees) {
int answer = 0;
// HashMap을 통해 각 자리가 몇 번째 순서인지 저장
HashMap<Character, Integer> hashMap = new HashMap<>();
for(int i = 0; i < skill.length(); i++) hashMap.put(skill.charAt(i), i);
for(String s: skill_trees) {
int idx = 0;
boolean flag = true;
// 0번째 인덱스부터 확인
// 해당 인덱스가 마지막까지 확인한 인덱스의 자릿수 크다면
// false 반환
for(int i = 0; i < s.length(); i++) {
if(hashMap.containsKey(s.charAt(i))) {
if(hashMap.get(s.charAt(i)) > idx) {
flag = false;
break;
}
}
if(s.charAt(i) == skill.charAt(idx)) idx++;
if(idx == skill.length()) break;
}
if(flag) answer++;
}
return answer;
}
}