inblog logo
|
silver
    알고리즘문제풀기

    [알고리즘문제풀기] n 번째 원소부터

    silver's avatar
    silver
    Mar 07, 2025
    [알고리즘문제풀기] n 번째 원소부터
    Contents
    문제내가 작성한 정답다른 사람들의 정답

    문제

    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/181892

    내가 작성한 정답

    Array

    class Solution { public int[] solution(int[] num_list, int n) { int[] answer = new int[num_list.length-n+1]; for(int i=0; i< num_list.length-n+1; i++){ answer[i] = num_list[n+i-1]; } return answer; } }

    StreamAPI

    import java.util.stream.*; class Solution { public int[] solution(int[] num_list, int n) { return IntStream.range(n-1,num_list.length) .map(i->num_list[i]).toArray(); } }

    다른 사람들의 정답

    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; } }
    Share article

    silver

    RSS·Powered by Inblog