취미처럼

[프로그래머스] 숫자의 표현 본문

Algorithm/Programmers

[프로그래머스] 숫자의 표현

sirius 2021. 3. 15. 09:47
https://school.programmers.co.kr/learn/courses/30/lessons/12924

 

class Solution {
    public int solution(int n) {
        int answer = 1; // 자기자신 n
        for(int i = 1; i <= n / 2 ; i++) { // 절반을 넘어가면 연속해서 더한 값이 n을 넘게 됨
            int sum = i;
            for(int j = i + 1; sum < n; j++) {
            	sum += j;
            }
            if(sum == n) {
            	answer ++;
            }
        }
        return answer;
    }
}

'Algorithm > Programmers' 카테고리의 다른 글

[프로그래머스] 연속된 수의 합  (0) 2021.03.15
[프로그래머스] 옹알이  (0) 2021.03.15
[프로그래머스] 네트워크  (0) 2021.03.15
[프로그래머스] 도둑질  (0) 2021.03.08
Comments