문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/64064
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
코드:
import java.util.*;
class Solution {
Set<Set<String>> answer = new HashSet<>();
List<List<String>> userIdList = new ArrayList<>();
public int solution(String[] user_id, String[] banned_id) {
for (int i = 0; i < banned_id.length; i++) {
String banId = banned_id[i];
List<String> list = new ArrayList<>();
label : for (String userId : user_id) {
if (banId.length() == userId.length()) {
for (int j = 0; j < banId.length(); j++) {
if(banId.charAt(j) == '*') continue;
else{
if(banId.charAt(j) != userId.charAt(j)) continue label; //다음 userId 확인
}
}
list.add(userId);
}
}
userIdList.add(list);
}
// 조합
recur(0, new HashSet<>());
return answer.size();
}
public void recur(int cur, Set<String> set){
if (cur == userIdList.size()) {
answer.add(set);
return;
}
List<String> userIds = userIdList.get(cur);
for (String userId : userIds) {
if (!set.contains(userId)) {
Set<String> tmp = new HashSet<>(set);
tmp.add(userId);
recur(cur + 1, tmp);
}
}
}
}
public class Main {
public static void main(String[] args) {
Solution sol = new Solution();
String[] user_id = {
"frodo", "fradi", "crodo", "abc123", "frodoc"
};
String[] banned_id = {
"fr*d*", "abc1**"
};
int result = 2;
int answer = sol.solution(user_id, banned_id);
System.out.println(answer == result);
}
}
'PS > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 등굣길 - JAVA(자바) (1) | 2023.11.17 |
---|---|
[프로그래머스] 수식 최대화 - 자바 (0) | 2023.11.16 |
[프로그래머스] 양궁대회 - JAVA(자바) (0) | 2023.11.11 |
프로그래머스 2023 KAKAO BLIND RECRUITMENT - 이모티콘 할인행사[JAVA] (0) | 2023.11.10 |
프로그래머스 2020 KAKAO BLIND RECRUITMENT - 자물쇠와 열쇠[JAVA] (0) | 2023.11.09 |