프로그래머스 LEVEL 2(위장)
-
사용 언어 : javascript
-
해결 날짜 : 2022-10-13
- 해결 방법 :
- 예전에 c++로 풀었던 문제를 다시 풀어 보았다.
- 옷의 이름은 중요하지 않으므로 Map()을 이용해 종류 별 개수를 저장
- map을 돌며 종류 별 경우의 수 구함
- 회고 :
- x
-
코드
function solution(clothes) { let answer = 0; const map = new Map(); for (const cloth of clothes) { const [name, kind] = cloth; if (map.has(kind)) map.set(kind, map.get(kind) + 1); else map.set(kind, 1); } map.forEach((value, key) => { answer += value + value * answer; }); return answer; }
- 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges