Skip to content

Commit 048c234

Browse files
[BaekJoon] 암호 만들기
1 parent 8b644e4 commit 048c234

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

BaekJoon/암호 만들기.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Foundation
2+
3+
let LC = readLine()!.split(separator: " ").map { Int(String($0))! }
4+
let characters = readLine()!.split(separator: " ").map { String($0) }
5+
6+
func solution(L: Int, characters: [String]) -> [String] {
7+
let charArr = characters.sorted()
8+
var resultArr: [String] = []
9+
10+
func dfs(depth: Int, visited: String) {
11+
if visited.count == L {
12+
if visited.filter({ "aeiou".contains($0) }).count >= 1 &&
13+
visited.filter({ !"aeiou".contains($0) }).count >= 2 {
14+
resultArr.append(visited)
15+
}
16+
return
17+
}
18+
guard depth < characters.count else { return }
19+
20+
dfs(depth: depth + 1, visited: visited + charArr[depth])
21+
dfs(depth: depth + 1, visited: visited)
22+
}
23+
24+
dfs(depth: 0, visited: "")
25+
26+
return resultArr
27+
}
28+
29+
solution(L: LC[0], characters: characters).forEach {
30+
print($0)
31+
}

0 commit comments

Comments
 (0)