import java.util.ArrayList;
import java.util.List;
class Solution {
public static List<Integer> solution(int[] num_list, int n) {
List<Integer> list = new ArrayList<>();
for(int i = 0; i < num_list.length; i++){
if(n != num_list.length) {
list.add(num_list[n]);
}else{
n = 0;
list.add(num_list[n]);
}
n++;
}
return list;
}
}
list를 이용해서 n을 수정해가며 추가하는 식으로 처리했다
import java.util.stream.IntStream;
class Solution {
public int[] solution(int[] num_list, int n) {
return IntStream.range(0, num_list.length).map(i -> num_list[(i + n) % num_list.length]).toArray();
}
}
이런 식으로 나머지 연산을 통해서 n 을 0으로 초기화시킬 필요없이 나머지 처리로 할 수 도 있다. 이 방법을 활용할 생각을 못하다니
다음에는 꼭 활용해야겠다.