File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments