/*
n: the number of socks in the pile
ar: the colors of each sock
양말 색깔 별로 세트 몇개를 팔 수 있는가?
*/
func sockMerchant(n: Int, ar: [Int]) -> Int {
let colors = Set(ar)
var result: Int = 0
for color in colors {
var set: Int = 0
ar.map {
if $0 == color {
set += 1
}
}
result += (set / 2)
}
return result
}
sockMerchant(n: 9, ar: [10, 20, 20, 10, 10, 30, 50, 10, 20])
'알고리즘 > 해커랭크' 카테고리의 다른 글
해커랭크 - formingMagicSquare (0) | 2020.09.15 |
---|---|
해커랭크 - climbingLeaderboard (0) | 2020.09.15 |
해커랭크 - getMoneySpent (0) | 2020.09.14 |
해커랭크 - CountingValleys (0) | 2020.09.14 |
해커랭크 - Bon Appetit (0) | 2020.09.14 |