Skip to content

Commit c2e91f0

Browse files
committed
[level 0] Title: 2차원으로 만들기, Time: 0.02 ms, Memory: 84.3 MB -BaekjoonHub
1 parent 6bb6f7f commit c2e91f0

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int[][] solution(int[] num_list, int n) {
3+
int length = num_list.length;
4+
int col = n;
5+
int row = length/col;
6+
7+
int[][] answer = new int [row][col];
8+
int idx = 0;
9+
10+
for(int i=0; i<row; i++){
11+
for(int j=0; j<col; j++){
12+
answer[i][j] = num_list[idx++];
13+
}
14+
}
15+
16+
17+
return answer;
18+
}
19+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# [level 0] 2차원으로 만들기 - 120842
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120842?language=java)
4+
5+
### 성능 요약
6+
7+
메모리: 84.3 MB, 시간: 0.02 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩테스트 입문
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 05월 04일 23:24:41
20+
21+
### 문제 설명
22+
23+
<p>정수 배열 <code>num_list</code>와 정수&nbsp;<code>n</code>이 매개변수로 주어집니다. <code>num_list</code>를 다음 설명과 같이 2차원 배열로 바꿔 return하도록 solution 함수를 완성해주세요.</p>
24+
25+
<p><code>num_list</code>가 [1, 2, 3, 4, 5, 6, 7, 8] 로 길이가 8이고 <code>n</code>이 2이므로 <code>num_list</code>를 2 * 4 배열로 다음과 같이 변경합니다. 2차원으로 바꿀 때에는 num_list의 원소들을 앞에서부터 n개씩 나눠 2차원 배열로 변경합니다.</p>
26+
<table class="table">
27+
<thead><tr>
28+
<th>num_list</th>
29+
<th>n</th>
30+
<th>result</th>
31+
</tr>
32+
</thead>
33+
<tbody><tr>
34+
<td>[1, 2, 3, 4, 5, 6, 7, 8]</td>
35+
<td>2</td>
36+
<td>[[1, 2], [3, 4], [5, 6], [7, 8]]</td>
37+
</tr>
38+
</tbody>
39+
</table>
40+
<hr>
41+
42+
<h5>제한사항</h5>
43+
44+
<ul>
45+
<li><code>num_list</code>의 길이는&nbsp;<code>n</code>의 배 수개입니다.</li>
46+
<li>0 ≤ <code>num_list</code>의 길이 ≤ 150</li>
47+
<li>2 ≤ <code>n</code> &lt; <code>num_list</code>의 길이</li>
48+
</ul>
49+
50+
<hr>
51+
52+
<h5>입출력 예</h5>
53+
<table class="table">
54+
<thead><tr>
55+
<th>num_list</th>
56+
<th>n</th>
57+
<th>result</th>
58+
</tr>
59+
</thead>
60+
<tbody><tr>
61+
<td>[1, 2, 3, 4, 5, 6, 7, 8]</td>
62+
<td>2</td>
63+
<td>[[1, 2], [3, 4], [5, 6], [7, 8]]</td>
64+
</tr>
65+
<tr>
66+
<td>[100, 95, 2, 4, 5, 6, 18, 33, 948]</td>
67+
<td>3</td>
68+
<td>[[100, 95, 2], [4, 5, 6], [18, 33, 948]]</td>
69+
</tr>
70+
</tbody>
71+
</table>
72+
<hr>
73+
74+
<h5>입출력 예 설명</h5>
75+
76+
<p>입출력 예 #1</p>
77+
78+
<ul>
79+
<li><code>num_list</code>가 [1, 2, 3, 4, 5, 6, 7, 8] 로 길이가 8이고 <code>n</code>이 2이므로 2 * 4 배열로 변경한 [[1, 2], [3, 4], [5, 6], [7, 8]] 을 return합니다.</li>
80+
</ul>
81+
82+
<p>입출력 예 #2</p>
83+
84+
<ul>
85+
<li><code>num_list</code>가 [100, 95, 2, 4, 5, 6, 18, 33, 948] 로 길이가 9이고 <code>n</code>이 3이므로 3 * 3 배열로 변경한 [[100, 95, 2], [4, 5, 6], [18, 33, 948]] 을 return합니다.</li>
86+
</ul>
87+
88+
89+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges

0 commit comments

Comments
 (0)