코딩테스트/JAVA 코테

머쓱이보다 키큰 사람

박소민 2023. 2. 7. 00:36
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();
    }
}