Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- APNS
- 오블완
- modern concurrency deep dive
- 티스토리챌린지
- 야곰 # 야곰아카데미커리어스타터캠프 #iOS개발자 # 부트캠프
- WWDC
- ios
- SWIFT
- modern concurrency
Archives
- Today
- Total
Geon
신고 결과 받기 본문
코드
import Foundation
func solution(_ id_list:[String], _ report:[String], _ k:Int) -> [Int] {
var dict: [String: [String]] = [:]
var result = Array(repeating: 0, count: id_list.count)
var countDict: [String:Int] = [:]
for (index, id) in id_list.enumerated() {
countDict[id] = index
}
for repo in report {
let arr = repo.split(separator: " ").compactMap {String($0)}
let beAccused = arr[1]
let accusation = arr[0]
if dict[beAccused] == nil {
dict.updateValue([accusation], forKey: beAccused)
} else {
if !dict[beAccused]!.contains(accusation) {
dict[beAccused]!.append(accusation)
}
}
}
for i in dict.keys {
if dict[i]!.count >= k {
for n in dict[i]! {
result[countDict[n]!] += 1
}
}
}
return result
}
배운점
- Array(repeating:,count:) 를 통해 배열안에 있는 요소의 갯수를 지정 가능
- 딕셔너리의 인덱스를 지정할수 있다.
'코딩테스트' 카테고리의 다른 글
단어뒤집기[BOJ] (0) | 2022.03.22 |
---|---|
스택[BOJ] (0) | 2022.03.22 |
로또의 최고 순위와 최저 순위 (0) | 2022.03.16 |
신규 아이디 추천 (0) | 2022.03.15 |
숫자 문자열과 영단어 (0) | 2022.03.15 |