코틀린 fold1 [프로그래머스] 의상 (kotlin) class Solution { fun solution(clothes: Array>): Int { var answer = 0 val hashMap : HashMap = HashMap() for(i in 0 until clothes.size){ hashMap[clothes[i][1]]=hashMap.getOrDefault(clothes[i][1],1)+1 } answer=hashMap.values.fold(1,{acc,number->acc*number})-1 return answer }}1. 해시 맵을 사용하여 의상의 종류 갯수를 구해준다. 해시 맵의 key는 의상의 종류 이름(String)으로 하고, .. 2024. 12. 29. 이전 1 다음