본문 바로가기
프로그래머스/[프로그래머스 - JAVA] Lv.1

[프로그래머스 - JAVA] 약수의 합

by 코딩하는 흰둥이 2023. 3. 25.
반응형


  • 내 풀이
class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for (int i = 1; i <= n; i++) {
            if (n % i == 0){
                answer += i;
            }
        }
        return answer;
    }
}

 

class Solution {
    public int solution(int n) {
        int answer = 0;
		for (int i = 1; i <= n/2; i++) {
            if (n % i == 0){
                answer += i;
            }
        }
                return answer;
    }
}

 

댓글