Written by
java-style
on
on
[프로그래머스] 소수 찾기-완전탐색 Level2
[프로그래머스] 소수 찾기-완전탐색 Level2
- 풀이
백트래킹으로 모든 경우의수를 찾아주고
에라토스테네스 체를 이용하여 소수만 HashSet에 add한다. (HashSet은 중복제거를 위해 사용함)
import java.util.HashSet; class Solution { static char[] arr; static int[] ch; static HashSet set; public static boolean isPossible(int num) { if (num<=1) return false; for (int i=2; i(); ch = new int[numbers.length()]; for (int i=1; i<=numbers.length(); i++) { arr = new char[i]; DFS(0,i,numbers); } answer=set.size(); return answer; } }
from http://rotomoo.tistory.com/19 by ccl(A) rewrite - 2021-11-01 19:01:48