import java.util.*;
class Solution {
public int[] solution(int[] num_list) {
int[] answer = new int[5];
Arrays.sort(num_list);
for(int i=0; i<5; i++) {
answer[i] = num_list[i];
}
return answer;
}
}
아... limit이 있구나..! 타인의 풀이 ▼
import java.util.*;
class Solution {
public int[] solution(int[] num_list) {
return Arrays.stream(num_list)
.sorted()
.limit(5)
.toArray();
}
}
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 n개간격의원소들 // toArray() (0) | 2023.12.12 |
---|---|
프로그래머스 - L0 배열의길이에따라다른연산하기 (0) | 2023.12.11 |
프로그래머스 - L0 문자열바꿔서찾기 // String class method (0) | 2023.12.11 |
프로그래머스 - L0 접미사인지확인하기 (1) | 2023.12.08 |
프로그래머스 - L0 조건에맞게수열변환하기1 (1) | 2023.12.08 |