[프로그래머스 | C# | Lv.0] 2차원으로 만들기

728x90

프로그래머스-002 (10).png

 

https://school.programmers.co.kr/learn/courses/30/lessons/120842

 

etc-image-1

 

📝 나의 풀이

using System;

public class Solution {
    public int[,] solution(int[] num_list, int n) {
        int[,] answer = new int[(num_list.Length/n), n];
        
        int x = 0;
        int y = 0;
        
        for(int i=0; i<num_list.Length; i++)
        {
            answer[x, y] = num_list[i];
            y++;
            if(y == n)
            {
                x++;
                y = 0;
            }
        }
        return answer;
    }
}
728x90