본문 바로가기

CS/프로그래머스코딩테스트

2중 for문 주의점

class Solution {
    public int solution(int n) {
        int answer = 0;

        for(int j =1; j<=n;j++){
              int count = 0;
            //1~n
            for(int i=1; i<=j; i++){

                if(j%i==0){
                    ++count;
                }
            }
            if(count >=3){
                ++answer;
            }
        }
        return answer;
    }
}

2중 for문 돌릴 때, 변수 초기화 위치 주의. 

'CS > 프로그래머스코딩테스트' 카테고리의 다른 글

소인수분해  (0) 2023.09.21
문자열 치환  (0) 2023.09.18
배열 원소의 길이  (0) 2023.09.14
List를 Array로 변환하기  (0) 2023.08.29
최빈값 구하기  (0) 2023.04.18