[Programmers] #181892 - n 번째 원소부터 [Java][C++][Python]
[Programmers] #181892 - n 번째 원소부터 [Java][C++][Python]
1. 아이디어
$n$번째 원소는 1부터 센 번호라 인덱스로는 $n - 1$이다. 그래서 인덱스 $n - 1$부터 끝까지 자르면 된다.
2. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
6
7
import java.util.*;
class Solution {
public int[] solution(int[] num_list, int n) {
return Arrays.copyOfRange(num_list, n - 1, num_list.length);
}
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;
vector<int> solution(vector<int> num_list, int n) {
return vector<int>(num_list.begin() + n - 1, num_list.end());
}
1
2
def solution(num_list, n):
return num_list[n - 1 :]
This post is licensed under CC BY 4.0 by the author.