본문 바로가기
Algorithm/프로그래머스

[Algorithm / Programmers] 숫자의 표현

by newtownboy 2024. 4. 3.


[Version]
⦁ 2024.04.03 / [Algorithm / Programmers] 숫자의 표현

 

class Solution {
    public int solution(int n) {
        int totalCount = 0;
        for (int i = 1; i <= n; i++) {
            int sum = 0;
            for (int j = i; j <= n; j++) {
                sum += j;
                if (sum == n) {
                    totalCount++;
                    break;
                }
                if (sum > n) {
                    break;
                }
            }
        }
        
        return totalCount;
    }
}