[Level2] n^2배열자르기
n^2배열자르기
function solution(n, left, right) {
const arr = Array.from(Array(n), () => Array(n).fill(0));
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
arr[i][j] = i >= j ? i + 1 : j + 1;
}
}
let splitArr = [];
for (let i = 0; i < n; i++) {
splitArr = [...splitArr, ...arr[i]];
}
return splitArr.slice(left, right + 1);
}
function solution(n, left, right) {
const ans = [];
while (left <= right) {
ans.push(Math.max(Math.floor(left / n), left % n) + 1);
left++
}
return ans;
}