공대생의 비망록

[프로그래머스][Lv. 2] 위장 Swift 풀이 본문

Programming Language/Swift

[프로그래머스][Lv. 2] 위장 Swift 풀이

myungsup1250 2022. 5. 17. 17:59

https://programmers.co.kr/learn/courses/30/lessons/42578

 

코딩테스트 연습 - 위장

 

programmers.co.kr

 

C++로도 푼 문제!

C++ 풀이 : https://youngdeveloper.tistory.com/144

 

[C++][Lv. 2] 위장 C++ 풀이

https://programmers.co.kr/learn/courses/30/lessons/42578 코딩테스트 연습 - 위장 programmers.co.kr 풀이는 추후에 차차 올리도록 하겠습니다... <디버깅을 위한 기능이 포함된 첫 제출 코드> 1 2 3 4 5 6 7 8..

youngdeveloper.tistory.com

 

 

풀이는 추후에 차차 올리도록 하겠습니다...

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import Foundation
 
func solution(_ clothes:[[String]]) -> Int {
    var clothesMap: [String:[String]] = [String:[String]]()
    
    for cloth in clothes {
        if clothesMap[cloth[1]] == nil {
            clothesMap.updateValue([String](), forKey: cloth[1])
        }
        clothesMap[cloth[1]]!.append(cloth[0])
    }
    
    var answer = 1
    for (type, clothes) in clothesMap {
        answer *= clothes.count + 1  
    }  
    
    return answer - 1
}
 
cs
Comments