Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] 모음 사전 #201

Closed
hwangJi-dev opened this issue Apr 13, 2023 · 0 comments
Closed

[Algorithm] 모음 사전 #201

hwangJi-dev opened this issue Apr 13, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Apr 13, 2023

💬 문제

https://school.programmers.co.kr/learn/courses/30/lessons/84512


💬 Idea

  • DFS로 순차 탐색을 진행하며 모음 사전의 순번을 dict에 저장한다.

💬 풀이

import Foundation

var wordDict: [String: Int] = [:]
var count = 0

func solution(word:String) -> Int {
    dfs(words: [])
    return wordDict[word]!
}

func dfs(words: [String]) {
    wordDict[words.joined()] = count
    
    if words.count == 5 {
        return
    } else {
        for i in ["A", "E", "I", "O", "U"] {
            count += 1
            dfs(words: words + [i])
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant