SW Test/Programmers

[Programmers] Lv2.๋ชจ์Œ์‚ฌ์ „(kotlin)

An effort will never betray ๐Ÿ˜Ž 2022. 10. 22. 18:22
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

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

 

 

 

์˜ˆ์‹œ

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

 

 

 

ํ’€์ด

  • ๋ฐฑํŠธ๋ž˜ํ‚น ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
class Solution {
    val list = mutableSetOf<String>()
    
    fun getResult(word: String,idx: Int, str: String){
        if(idx == str.length){
            list.add(word)
        }else{
            for(ch in str){
                getResult(word + ch, idx+1, str)
            }
            getResult(word, idx+1, str)
        }
    }
    
    fun solution(word: String): Int {
        getResult("", 0, "AEIOU")
        return list.toList().sorted().indexOf(word)
    }
}

 

 

 

์ฐธ๊ณ 

  • ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ธ kotlin์˜ ํŠน์„ฑ์— ๋งž๊ฒŒ ํ•จ์ˆ˜๋ฅผ ๋งŽ์ด ์ตํžˆ์ž ๐Ÿ˜ฝ
๋ฐ˜์‘ํ˜•