프로그래머스 - level 0 배열의 원소만큼 추가하기
import java.util.*;
import java.util.stream.*;
import java.util.List;
class Solution {
public int[] solution(int[] arr) {
List<Integer> answer = new ArrayList<>();
for(int i=0; i<arr.length; i++) {
int k = arr[i];
for(int j=0; j<k; j++) {
answer.add(k);
}
}
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}
arr.stream().mapToInt(Integer::intValue).toArray();
밖에 없나 진짜???
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 공백으로구분하기2 // 정규표현식 (0) | 2023.12.22 |
---|---|
프로그래머스 - L0 두수의연산값비교하기 // String ↔ int (0) | 2023.12.21 |
프로그래머스 - L0 배열비교하기 (0) | 2023.12.20 |
프로그래머스 - L0 카운트다운 // IntStream.rangeClosed() (0) | 2023.12.19 |
프로그래머스 - L0 꼬리문자열 (0) | 2023.12.19 |