We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main.java.com.poogle.PG.Q64064; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; public class Solution { private static Set<Set<String>> result; public static void main(String[] args) { System.out.println(solution(new String[]{"frodo", "fradi", "crodo", "abc123", "frodoc"}, new String[]{"fr*d*", "abc1**"})); System.out.println(solution(new String[]{"frodo", "fradi", "crodo", "abc123", "frodoc"}, new String[]{"*rodo", "*rodo", "******"})); System.out.println(solution(new String[]{"frodo", "fradi", "crodo", "abc123", "frodoc"}, new String[]{"fr*d*", "*rodo", "******", "******"})); } public static int solution(String[] user_id, String[] banned_id) { result = new HashSet<>(); dfs(user_id, banned_id, new LinkedHashSet<>()); return result.size(); } private static void dfs(String[] user_id, String[] banned_id, Set<String> set) { if (set.size() == banned_id.length) { if (isBanned(set, banned_id)) { result.add(new HashSet<>(set)); } return; } for (String user : user_id) { if (!set.contains(user)) { set.add(user); dfs(user_id, banned_id, set); set.remove(user); } } } private static boolean isBanned(Set<String> set, String[] banned_id) { int i = 0; for (String user : set) { if (!isSameString(user, banned_id[i++])) return false; } return true; } private static boolean isSameString(String user, String ban) { if (user.length() != ban.length()) return false; for (int i = 0; i < user.length(); i++) { if (ban.charAt(i) == '*') continue; if (user.charAt(i) != ban.charAt(i)) return false; } return true; } }
The text was updated successfully, but these errors were encountered:
d4e24d2
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: