728x90
๋ฐ์ํ
Problem
Solution
1. ๋ถ๋ ์ฌ์ฉ์์ ์ ์ ์์ด๋๋ฅผ ๋น๊ตํ๋ค.
func isEqual(userId:String,bannedId:String) -> Bool {
if userId.count != bannedId.count { return false }
let uid = userId.map{String($0)}
let bid = bannedId.map{String($0)}
for (i,b) in bid.enumerated() {
if b != "*" && uid[i] != bid[i] {
return false
}
}
return true
}
2. ๋น๊ตํ ์์ด๋ ์ค ํด๋นํ๋ ์์ด๋๋ฅผ ๋ฐ๋ก ๋ชจ์๋๋๋ค.
func findBanIdEqualUserId(userId:[String],banId:[String]) -> [[Int]] {
var banArray = Array(repeating: [Int](), count: banId.count)
for (i,uid) in userId.enumerated() {
for (j,bid) in banId.enumerated() {
if isEqual(userId: uid, bannedId: bid) {
banArray[j].append(i)
}
}
}
return banArray
}
3. ๋ถ๋์ฌ์ฉ์๋ค์ ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๋ค.
func insertBanIdsToResult(banArray:[[Int]],banIds:Set<Int>,result:inout Set<[Int]>,current:Int) {
for id in banArray[current] {
var newBanIds = banIds
newBanIds.insert(id)
if current != banArray.count - 1 {
insertBanIdsToResult(banArray:banArray,banIds: newBanIds,result:&result ,current: current+1)
}else if newBanIds.count == banArray.count {
result.insert(newBanIds.sorted())
}
}
}
4. ๊ฒฝ์ฐ์ ์์ ๊ฐฏ์๋ฅผ ๋ฐํํ๋ค.
return result.count
Source Code
728x90
๋ฐ์ํ
'๐ Problem Solution > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] 2021 KAKAO INTERNSHIP ํํธ์ง (0) | 2021.07.18 |
---|---|
[Swift] ํ๋ก๊ทธ๋๋จธ์ค ์๊ฐ ์ฝ๋ ์ฑ๋ฆฐ์ง 2 2๊ฐ ์ดํ๋ก ๋ค๋ฅธ ๋นํธ (0) | 2021.07.03 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค ๊ฐ์ฅ ๊ธด ํฐ๋ฆฐ๋๋กฌ (0) | 2021.06.22 |
[Swift] 2019 KAKAO BLIND RECRUITMENT ๊ธธ ์ฐพ๊ธฐ ๊ฒ์ (0) | 2021.06.11 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค ์ซ์ ๊ฒ์ (0) | 2021.06.11 |
๋๊ธ