Hi, There!
안녕하세요, 바오밥입니다.
목차
- 문제
- 풀이
문제
문제 내용
https://school.programmers.co.kr/learn/courses/30/lessons/120842
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
나의 풀이
class Solution {
public int[][] solution(int[] num_list, int n) {
int[][] answer = new int[num_list.length/n][n];
int oneIdx = 0;
int twoIdx = 0;
for(int i=0; i<num_list.length; i++) {
answer[oneIdx][twoIdx] = num_list[i]; // 00 01 10 11 20 21 30 31
if(twoIdx == n-1) {
twoIdx = 0;
oneIdx++;
continue;
}
twoIdx++;
}
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;
}
}
'Dev > PS' 카테고리의 다른 글
[프로그래머스-코딩테스트 입문] 배열 회전시키기 (0) | 2023.05.28 |
---|---|
[프로그래머스-코딩테스트 입문] 공 던지기 (0) | 2023.05.28 |
[프로그래머스-코딩테스트 입문] 점의 위치 구하기 (0) | 2023.05.28 |
[프로그래머스-코딩 기초 트레이닝] 특정한 문자를 대문자로 바꾸기 (0) | 2023.05.28 |
[프로그래머스-코딩 기초 트레이닝] A 강조하기 (0) | 2023.05.28 |