알고리즘 문제풀이/Programmers - 자바
프로그래머스 - 소수 찾기
올리브영
2023. 4. 3. 18:24
728x90
반응형
class Solution {
public int solution(int n) {
int answer = 0;
boolean[] check = new boolean[n+1];
for(int i=2; i<=n; i++){
if(check[i] == true) continue;
for(int j=i*2; j<=n; j=j+i){
check[j] = true;
}
}
for(int i=2; i<=n; i++){
if(!check[i]){
answer++;
}
}
return answer;
}
}
728x90
반응형