ํ๋ก๊ทธ๋๋จธ์ค - ๋ชจ์์ฌ์ (Swift)
2022. 10. 21. 21:25ใํ๋ก๊ทธ๋๋จธ์ค-Swift
ํ๋ก๊ทธ๋๋จธ์ค - ๋ชจ์์ฌ์ (Swift)
๋ฌธ์ ์ค๋ช
https://school.programmers.co.kr/learn/courses/30/lessons/84512
๋์ ํ์ด
5๊ฐ์ ์์๋ง ๋๋ฉด ๋๊ธฐ ๋๋ฌธ์ ์์ ํ์ DFS๋ก ๋ฌธ์ ๋ฅผ ํ์๋ค.
import Foundation
func solution(_ word:String) -> Int {
var dic: [String: Int] = [:]
func DFS(_ L: Int, _ accStr: String) {
if L != 0 {
cnt += 1
dic[accStr] = cnt
}
if L == arr.count {
return
} else {
for i in 0..<5 {
DFS(L+1, accStr + arr[i])
}
}
}
let arr: [String] = ["A", "E", "I", "O", "U"]
var cnt = 0
DFS(0, "")
return dic[word]!
}
'ํ๋ก๊ทธ๋๋จธ์ค-Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค - ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ (0) | 2022.10.22 |
---|---|
ํ๋ก๊ทธ๋๋จธ์ค - 2๊ฐ ์ดํ๋ก ๋ค๋ฅธ ๋นํธ (1) | 2022.10.22 |
ํ๋ก๊ทธ๋๋จธ์ค - ํ์ผ๋ช ์ ๋ ฌ(Swift) (0) | 2022.10.21 |
ํ๋ก๊ทธ๋๋จธ์ค - ๋ฐฉ๋ฌธ ๊ธธ์ด(Swift) (0) | 2022.10.20 |
ํ๋ก๊ทธ๋๋จธ์ค - ์คํฌํธ๋ฆฌ(Swift) (0) | 2022.10.20 |