Develop

[프로그래머스] 카운트 다운 본문

개인 공부/프로그래머스

[프로그래머스] 카운트 다운

개발 기록 2024. 1. 23. 17:33

문제

 

 

내풀이

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();
    }
}