- 난이도: Lv2
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/87390
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/2/n^2 배열 자르기
입출력 예 #1
입출력 예 #2
풀이 시간 : 17분
public class Solution {
public int[] solution(int n, long left, long right) {
int len = (int) (right - left + 1);
int[] answer = new int[len];
for (int i = 0; i < len; i++) {
long index = left + i;
int row = (int) (index / n);
int col = (int) (index % n);
answer[i] = Math.max(row, col) + 1;
}
return answer;
}
}