내일배움캠프 41일차 TIL _ 9주 3일차
2024. 6. 12. 21:26ㆍTIL Java
- 오늘 있었던 일
- 팀과제
- 알고리즘
SPRIONG
- 스프링 정리
알고리즘 문제 풀기
● n^2 배열 자르기
더보기
● n^2 배열 자르기 //링크
class Solution {
public int[] solution(int n, long left, long right) {
int size = (int) (right - left + 1);
int[] answer = new int[size];
for (long i = left; i <= right; i++) {
answer[(int) (i - left)] = (int) (Math.max(i / n, i % n) + 1);
}
return answer;
}
}
- 두번만에 통과했다.
- 전체를 구하고 각 수를 배열로 만들어 봤다
- 전체를 2중 배열로 구한 다음 1중 배열로 만들어 그 수에서 인덱스를 구했다 = 메모리 초과
- 아에 계산식으로 해당 위치를 구했다.
- 전체를 구하고 각 수를 배열로 만들어 봤다
- 밑은 다른 사람의 풀이
-
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(); } }
- 한줄로 했다고?!
당일 회고
- Mockito... 뭐라 말하기 어렵다.
'TIL Java' 카테고리의 다른 글
내일배움캠프 43일차 TIL _ 9주 5일차 (0) | 2024.06.14 |
---|---|
내일배움캠프 42일차 TIL _ 9주 4일차 (0) | 2024.06.13 |
내일배움캠프 40일차 TIL _ 9주 2일차 (0) | 2024.06.11 |
내일배움캠프 39일차 TIL _ 9주 1일차 (0) | 2024.06.10 |
내일배움캠프 38일차 TIL _ 8주 4일차 (1) | 2024.06.07 |