


import java.util.Arrays;
import java.util.HashSet;
public class Solution {
static boolean[] check;
static HashSet<String> set;
public static int solution(String[] user_id, String[] banned_id) {
check = new boolean[user_id.length];
set = new HashSet<String>();
for(int i=0; i<banned_id.length; i++)
banned_id[i] = banned_id[i].replace('*', '.');
back(0,"",banned_id,user_id);
return set.size();
}
public static void back(int d, String res, String[] banned_id, String[] user_id) {
if(d==banned_id.length) {
String[] arr = res.split(" ");
Arrays.sort(arr);
String str="";
for(String s:arr) str+=s;
set.add(str);
return;
}
for(int i=0; i<user_id.length; i++) {
if(check[i] || !user_id[i].matches(banned_id[d])) continue;
check[i]=true;
back(d+1,user_id[i]+" "+res,banned_id,user_id);
check[i]=false;
}
}
}
'Algorithm & Data Structures > Programers' 카테고리의 다른 글
Lv 2. 이진변환 반복하기 (0) | 2024.04.09 |
---|---|
Lv 2. 올바른 괄호 (0) | 2024.04.08 |
Lv 2. 최댓값과 최소값 (0) | 2024.03.05 |
Lv2. 124 나라의 숫자 (Java) (0) | 2023.10.13 |
Lv2. 요격 시스템 (Java) (0) | 2023.10.12 |