[프로그래머스] 위장 - JAVA[자바]

doxxx·2023년 1월 11일
1

프로그래머스

목록 보기
4/17
post-thumbnail

이번 문제는 그냥 코드 공유만 하려고 한다.

import java.util.*;  
  
class Solution {  
  
    public int solution(String[][] clothes) {  
        Map<String, Integer> counts = new HashMap<>();  
  
        for (String[] clothe : clothes) {  
            String type = ;  
            counts.put(clothe[1], counts.getOrDefault(clothe[1], 0) + 1);  
        }  
  
        int answer = 1;  
        for (Integer count : counts.values()) {  
            answer *= count + 1;  
        }  
        return answer - 1;  
    }  
}
import java.util.*;  
  
class Solution {  
  
    public int solution(String[][] clothes) {  
        Map<String, Integer> counts = new HashMap<>();  
  
        for (String[] clothe : clothes) {  
            counts.put(clothe[1], counts.getOrDefault(clothe[1], 0) + 1);  
        }  
          
        return counts.values().stream().reduce(1, (a, b) -> a * (b + 1)) - 1;  
    }  
}
import java.util.*;  
import java.util.stream.*;  
  
class Solution {  
  
    public int solution(String[][] clothes) {  
        return Arrays.stream(clothes)  
                   .collect(Collectors.groupingBy(clothe -> clothe[1], Collectors.counting()))  
                   .values().stream().reduce(1L, (a, b) -> a * (b + 1)).intValue() - 1;  
    }  
}

0개의 댓글