SW Test/Programmers
[Programmers] Lv2.๋ชจ์์ฌ์ (kotlin)
An effort will never betray ๐
2022. 10. 22. 18:22
๋ฐ์ํ
๋ฌธ์
์์
ํ์ด
- ๋ฐฑํธ๋ํน ๊ธฐ๋ฒ์ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ํ ์ ์์ต๋๋ค.
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์ ํน์ฑ์ ๋ง๊ฒ ํจ์๋ฅผ ๋ง์ด ์ตํ์ ๐ฝ
๋ฐ์ํ