정수 n
이 매개변수로 주어질 때, n
의 약수를 오름차순으로 담은 배열을 return하도록 solution 함수를 완성해주세요.
n
≤ 10,000n | result |
---|---|
24 | [1, 2, 3, 4, 6, 8, 12, 24] |
29 | [1, 29] |
입출력 예 #1
입출력 예 #2
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int n) {
List<int> list = new List<int>();
for(int i = 1; i <= n; i++)
{
if(n % i == 0)
{
list.Add(i);
}
}
int[] answer = list.ToArray();
return answer;
}
}
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges