Algorithm/프로그래머스
[알고리즘] 순서 바꾸기 Java
rw-
2023. 5. 10. 21:28
728x90
import java.util.ArrayList;
import java.util.List;
class Solution {
public int[] solution(int[] num_list, int n) {
List<Integer> pre_List = new ArrayList<>();
for (int i = n; i < num_list.length; i++) {
pre_List.add(num_list[i]);
}
for (int i = 0; i < n; i++) {
pre_List.add(num_list[i]);
}
return pre_List.stream().mapToInt(Integer::intValue).toArray();
}
}
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();
}
}
728x90
반응형