내 답안
import java.util.ArrayList;
import java.util.Arrays;
class Solution {
public int[] solution(int start_num, int end_num) {
ArrayList<Integer> list = new ArrayList<>();
for(int i = start_num; i<=end_num; i++){
list.add(i);
}
int[] arr = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
arr[i] = list.get(i);
}
return arr;
}
}
Java
복사
다른 사람 풀이법
import java.util.stream.IntStream;
class Solution {
public int[] solution(int start, int end) {
return IntStream.rangeClosed(start, end).toArray();
}
}
Java
복사
class Solution {
public int[] solution(int start, int end) {
int[] answer = new int[end - start+1];
for(int i =0; i<= end - start; i++) {
answer[i] = start + i;
}
return answer;
}
}
Java
복사
import java.util.stream.*;
class Solution {
public int[] solution(int start, int end) {
return IntStream.rangeClosed(start, end).toArray();
}
}
Java
복사