
(Java) 프로그래머스 - 롤케이크 자르기
·
코딩 테스트
문제가 간단하지만 시간 제한을 맞추는게 꽤 까다로웠다. 인풋값이 크기 떄문에 O(n^2) 로직은 무조건 시간 초과가 나고, O(n log n) 이내로 작성해야 된다고 생각해서 최종적으로 O(n) 로직으로 풀이에 성공했다. 실패 코드 import java.util.*; import java.util.stream.Collectors; class Solution { public int solution(int[] topping) { int answer = 0; for(int i = 1; i < topping.length; i++) { Set set1 = Arrays.stream(Arrays.copyOfRange(topping, 0, i)) .boxed() .collect(Collectors.toSet()); S..