class Solution {
public int solution(int[] array, int height) {
int answer=0;
for (int n:array){
if (n>height){
answer+=1;
}
}
return answer;
}
}
- Arrays.stream(arr).filter( 인자 -> 인자[조건]) .toArray()
- 주어진 조건의 인자값만 배열로 생성
- ~~.count() 해서 개수 셈
import java.util.Arrays;
class Solution {
public int solution(int[] array, int height) {
return (int) Arrays.stream(array).filter(value -> value > height).count();
}
}'코딩테스트 > JAVA 코테' 카테고리의 다른 글
| [백준] [BFS] [Union-Find] 2606.바이러스 (0) | 2023.02.24 |
|---|---|
| [JAVA] [백준] [실버4] 1244.스위치 켜고 끄기 (0) | 2023.02.08 |
| 특정 문자 제거하기 (0) | 2023.02.07 |
| 아이스 아메리카노 (0) | 2023.02.06 |
| [Java] [프로그래머스] [Level 0] 문자반복 출력하기 (0) | 2023.02.06 |