목차
Problem Description
정수 n이 매개변수로 주어질 때, n의 약수를 오름차순으로 담은 배열을 return하도록 solution 함수를 완성해주세요.
Constraints:
1 ≤ n ≤ 10,000

My Solution (C#)
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int n) {
List<int> factors = new List<int>();
for(int i= 1; i <= n; i++)
{
if(n%i == 0)
{
factors.Add(i);
}
}
int[] answer = factors.ToArray();
return answer;
}
}
Generic 네임스페이스 사용 깜빡했었음
'Problem solving > Algorithms' 카테고리의 다른 글
| [프로그래머스] 자연수 뒤집어 배열로 만들기 (C#) (0) | 2025.07.15 |
|---|---|
| [LeetCode] 300. Longest Increasing Subsequence (0) | 2025.07.12 |
| [프로그래머스]최댓값과 최솟값 (C#) (0) | 2025.07.11 |
| [LeetCode] 733. Flood Fill (C#) (0) | 2025.07.09 |
| [프로그래머스]약수의 합 (C#) (0) | 2025.07.08 |