import java.util.*;
class Solution {
public int[] solution(int n, int k) {
List<Integer> answer = new ArrayList<>();
for(int i=1; i<=n; i++) {
if(i%k == 0)
answer.add(i);
}
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}
filter를 이렇게도 쓰는구나...
import java.util.stream.IntStream;
class Solution {
public int[] solution(int n, int k) {
return IntStream.rangeClosed(1, n).filter(i -> i % k == 0).toArray();
}
}
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 카운트다운 // IntStream.rangeClosed() (0) | 2023.12.19 |
---|---|
프로그래머스 - L0 꼬리문자열 (0) | 2023.12.19 |
프로그래머스 - L0 배열에서문자열대소문자변환하기 (0) | 2023.12.14 |
프로그래머스 - L0 이어붙인수 (0) | 2023.12.13 |
프로그래머스 - L0 뒤에서5등위로 // Stream & IntStream (0) | 2023.12.13 |