Solution 1) 내 풀이
import java.util.*;

class Solution {
    public int[] solution(int[] num_list, int n) {
        List<Integer> list = new ArrayList<>();
        
        for (int i = n - 1; i < num_list.length; i++) {
            list.add(num_list[i]);
        }
        return list.stream().mapToInt(Integer::intValue).toArray();
    }
}
Solution 2) 다른 사람의 풀이
import java.util.*;
class Solution {
    public int[] solution(int[] num_list, int n) {
        int[] a= Arrays.copyOfRange(num_list, n-1, num_list.length);
        return a;
    }
}
Arrays.copyOfRange(배열, 시작 위치, 끝위치)
간단하게 풀었지만 더 간단한 방법이 있었다.

 

+ Recent posts