Skip to content

Commit 28e4da4

Browse files
authored
[20250906] PGM / LV3 / 불량 사용자 / 김수연
[20250906] PGM / LV3 / 불량 사용자 / 김수연
2 parents 63595e3 + eb8d0ff commit 28e4da4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(String[] user_id, String[] banned_id) {
5+
HashSet<HashSet<String>> result = new HashSet<>();
6+
7+
dfs(new HashSet<>(), user_id, banned_id, result);
8+
return result.size();
9+
}
10+
11+
private void dfs(HashSet<String> hashset, String[] user_id, String[] banned_id, HashSet<HashSet<String>> result) {
12+
if (hashset.size() == banned_id.length) {
13+
result.add(new HashSet<>(hashset));
14+
return;
15+
};
16+
String target = banned_id[hashset.size()];
17+
18+
for (String user : user_id) {
19+
if (hashset.contains(user)) continue;
20+
if (check(target, user)) {
21+
hashset.add(user);
22+
dfs(hashset, user_id, banned_id, result);
23+
hashset.remove(user);
24+
}
25+
}
26+
}
27+
private boolean check(String target, String user) {
28+
if (target.length() != user.length()) return false;
29+
for (int j = 0; j < target.length(); j++) {
30+
if (target.charAt(j) == ('*')) continue;
31+
if (target.charAt(j) == user.charAt(j)) continue;
32+
return false;
33+
}
34+
return true;
35+
}
36+
}
37+
```

0 commit comments

Comments
 (0)