💻 문제 출처 : 프로그래머스_n^2 배열 자르기
class Solution {
public int[] solution(int n, long left, long right) {
int[] answer = new int[(int)(right - left) + 1];
int index = 0;
for(long i = left; i <= right; i++) {
int line = (int)(i / n);
int column = (int)(i % n);
answer[index] = Math.max(line, column) + 1;
index++;
}
return answer;
}
}
import java.util.Arrays;
import java.util.stream.LongStream;
class Solution {
public int[] solution(int n, long left, long right) {
return LongStream.rangeClosed(left, right).mapToInt(value -> (int) (Math.max(value / n, value % n) + 1)).toArray();
}
}