정답 1
이제는 딱 구상이 떠오른다. IntStream 에 filter.
import java.util.stream.IntStream;
class Solution {
public int solution(int[] array, int n) {
return IntStream.of(array).filter(d -> d == n).toArray().length;
}
}
정답 2
IntStream 이 아닌 Arrays 에 filter 를 사용할 수 도 있다.
import java.util.Arrays;
class Solution {
public int solution(int[] array, int n) {
return (int) Arrays.stream(array).filter(i -> i == n).count();
}
}
'프로그래머스 - 코딩테스트' 카테고리의 다른 글
[Java][프로그래머스] - LVL.0 숨어있는 숫자의 덧셈(1) (0) | 2023.02.02 |
---|---|
[Java][프로그래머스] - LVL.0 순서쌍의 개수 (0) | 2023.01.26 |
[Java][프로그래머스] - LVL.0 문자 반복 출력하기 (0) | 2023.01.25 |
[Java][프로그래머스] - LVL.0 최댓값 만들기(1) (0) | 2023.01.25 |
[Java][프로그래머스] - LVL.0 배열 자르기 (0) | 2023.01.24 |