File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments