Skip to content

Commit ac2af1b

Browse files
authored
Merge pull request #1272 from AlgorithmWithGod/lkhyun
[20251030] PGM / Lv2 / 스킬트리 / 이강현
2 parents 6c5b74c + d5e17a3 commit ac2af1b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(String skill, String[] skill_trees) {
5+
int answer = 0;
6+
List<Integer>[] adjList = new List[26];
7+
for(int i = 0; i<26; i++){
8+
adjList[i] = new ArrayList<>();
9+
}
10+
int[] degree = new int[26];
11+
12+
for(int i = 0; i<skill.length(); i++){
13+
for(int j = i+1; j<skill.length(); j++){
14+
adjList[skill.charAt(i) - 'A'].add(skill.charAt(j) - 'A');
15+
degree[skill.charAt(j) - 'A']++;
16+
}
17+
}
18+
19+
for(String s : skill_trees){
20+
int[] temp = degree.clone();
21+
boolean flag = true;
22+
for(int i = 0;i<s.length(); i++){
23+
if(temp[s.charAt(i) - 'A'] != 0){
24+
flag = false;
25+
break;
26+
}
27+
for(int a : adjList[s.charAt(i) - 'A']){
28+
temp[a]--;
29+
}
30+
}
31+
if(flag) answer++;
32+
}
33+
return answer;
34+
}
35+
}
36+
```

0 commit comments

Comments
 (0)