프로그래머스-숫자의 표현

이호영·2022년 4월 9일
0

프로그래머스-Level.2

목록 보기
28/36
class Solution {
    public int solution(int n) {
        int ans=0;;
        
        for(int i=1; i<=n/2; i++){
            if(sum(n,i))
                ans++;
        }
        
        
        return ans+1; //자기 자신 더하기
    }
    
    static boolean sum(int result, int n){
        int sum=0;
        while(sum<result){
            sum+=n;
            n++;
        }
        
        if(sum==result){
            return true;
        }else{
            return false;
        }
    }
}

0개의 댓글