Develop
[프로그래머스] 카운트 다운 본문
문제
내풀이
class Solution {
public int[] solution(int start, int end_num) {
int[] answer = new int[start-end_num+1];
for(int i=0; start >= end_num; i++){
answer[i] = start;
start--;
}
return answer;
}
}
다른 풀이1
import java.util.stream.IntStream;
class Solution {
public int[] solution(int start, int end) {
return IntStream.rangeClosed(-start, -end).map(i -> -i).toArray();
}
}
다른 풀이2
import java.util.stream.*;
import java.util.*;
class Solution {
public int[] solution(int start, int end) {
return IntStream.rangeClosed(end, start).boxed().collect(Collectors.toList()).stream().sorted(Comparator.reverseOrder()).mapToInt(Integer::intValue).toArray();
}
}
'개인 공부 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 수 조작하기1 (1) | 2024.01.25 |
---|---|
[프로그래머스] 마지막 두 원소 (0) | 2024.01.24 |
[프로그래머스] 카운트 업 (0) | 2024.01.21 |
[프로그래머스] 홀수 vs 짝수 (0) | 2024.01.20 |
[프로그래머스] 원소들의 곱과 합 (0) | 2024.01.19 |