https://school.programmers.co.kr/learn/courses/30/lessons/42839
https://mjmjmj98.tistory.com/50
import java.util.*;
class Solution {
public static int[] chk = new int[7];
public static Set<Integer> set = new HashSet<>();
public static boolean chkNumber(int num)
{
if(num <= 1) return false;
for(int i=2; i<= (int)Math.sqrt(num); i++)
{
if(num%i == 0)
{
return false;
}
}
return true;
}
public static void dfs(String word, String makeWord, int depth)
{
if(makeWord.length() == depth)
{
set.add(Integer.parseInt(makeWord));
}
for(int i=0; i<word.length(); i++)
{
if(chk[i] == 0)
{
chk[i] = 1;
dfs(word, makeWord + word.charAt(i), depth);
chk[i] = 0;
}
}
}
public static int solution(String word) {
int answer = 0;
for(int i=0; i<word.length(); i++)
{
dfs(word,"",i+1);
}
for(var num : set) {
if (chkNumber(num))
{
answer++;
}
}
return answer;
}
}
익힐것
1. Set set = new HashSet<>();
2.