

내가 작성한 코드
class Solution {
public int[][] solution(int[] num_list, int n) {
int[][] answer = new int[num_list.length / n][n];
for(int i = 0; i < num_list.length / n; i++) {
for(int j = 0; j < n; j++) {
answer[i][j] = num_list[i * n + j];
}
}
return answer;
}
}
다른 사람의 코드
class Solution {
public int[][] solution(int[] num_list, int n) {
int[][] answer = {};
int length = num_list.length;
answer = new int[length/n][n];
for(int i=0; i<length; i++){
answer[i/n][i%n]=num_list[i];
}
return answer;
}
}
나의 경우 이중 for문을 사용하였지만 다른 사람은 i / n 나눈 몫이랑 나머지로 배열에 값을 넣음
Share article