알고리즘1 연속된 자연수로 더하여 자연수 n이 될 수 있는 가지수 내가 짠 코드 - 재귀 함수를 이용, 1 부터 시작해서 자연수 n 까지 연속된 수로 더해서 n이 나올 수 있는지 여부를 체크 함. class Solution { public int solution(int n) { return countCase(1, n); } private int countCase(int start, int n) { if (start == n) { return 1; } int next = start * 2 + 1; if (next > n) { return countCase(++start, n); } int temp = n; for (int i = start; 0 < temp; i++) { temp -= i; } int isCase = temp < 0? 0 : 1; return countC.. 2023. 7. 9. 이전 1 다음