240305 n^2 배열 자르기

Jongleee·2024년 3월 5일
0

TIL

목록 보기
512/576
public int[] solution(int n, long left, long right) {
	int length = (int) (right - left) + 1;
	int[] answer = new int[length];

	for (int i = 0; i < length; i++) {
		long offset = i + left;
		answer[i] = calculateValue(n, offset);
	}

	return answer;
}

private int calculateValue(int n, long offset) {
	int row = (int) (offset / n) + 1;
	int col = (int) (offset % n) + 1;
	return Math.max(row, col);
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/87390

0개의 댓글