728x90
๋ฐ์ํ
Problem
Solution
1. id_list๋ฅผ ์ธ๋ฑ์ค์ ๋ง๊ฒ ๋์ ๋๋ฆฌ์ ๋ด๋๋ค.
var idNumber:[String:Int] = [:]
for (i,id) in id_list.enumerated() {
idNumber[id] = i
}
2. ์ ๊ณ ๋นํ ์ฌ๋์ ํค๊ฐ์ผ๋ก,์ ๊ณ ํ ์ฌ๋๋ค์ ๋ฐธ๋ฅ๊ฐ์ผ๋ก ๋์ ๋๋ฆฌ์ ๋ด๋๋ค.
var reportInfo:[String:Set<String>] = [:]
for r in report {
let split = r.split(separator: " ")
let report = String(split[0])
let reported = String(split[1])
if reportInfo[reported] == nil {
reportInfo[reported] = [report]
}else {
reportInfo[reported]!.insert(report)
}
}
3. k๋ณด๋ค ๋ ๋ง์ ์ ์ ๋ฅผ ์ ๊ณ ํ ์ ์ ์ ์นด์ดํธ๋ฅผ ์ธ์ค๋ค,
var reportCount:[Int] = Array(repeating: 0, count: id_list.count)
for info in reportInfo {
if info.value.count >= k {
for id in info.value {
reportCount[idNumber[id]!] += 1
}
}
}
4. reportCount๋ฅผ ๋ฐํํด์ค๋ค.
return reportCount
Source Code
728x90
๋ฐ์ํ
'๐ Problem Solution > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] 2022 KAKAO BLIND RECRUITMENT ์ฃผ์ฐจ ์๊ธ ๊ณ์ฐ (0) | 2022.01.19 |
---|---|
[Swift] 2022 KAKAO BLIND RECRUITMENT k์ง์์์ ์์ ๊ฐ์ ๊ตฌํ๊ธฐ (0) | 2022.01.19 |
[Swift] 2020 KAKAO BLIND RECRUITMENT ๊ฐ์ฌ ๊ฒ์ (0) | 2022.01.03 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค ์ง๊ฒ๋ค๋ฆฌ (with ์ฌ์ด ํ์ด ํฌํจ) (0) | 2022.01.03 |
[Swift] 2019 KAKAO BLIND RECRUITMENT ๋ฌด์ง์ ๋จน๋ฐฉ ๋ผ์ด๋ธ (0) | 2021.12.15 |
๋๊ธ