728x90
영어가 싫어요
class Solution {
fun solution(numbers: String): Long{
var answer = numbers
val number = mapOf<String, String>(
"one" to "1", "two" to "2", "three" to "3", "four" to "4", "five" to "5", "six" to "6",
"seven" to "7", "eight" to "8", "nine" to "9", "zero" to "0"
)
for (i in number){
answer = answer.replace(i.key, i.value)
}
return answer.toLong()
}
}
인덱스 바꾸기
class Solution {
fun solution(my_string: String, num1: Int, num2: Int): String {
var answer: String = ""
for (i in 0 until my_string.length){
if (i == num1) answer += my_string[num2]
else if (i == num2) answer += my_string[num1]
else answer += my_string[i]
}
return answer
}
}
한 번만 등장한 문자
class Solution {
fun solution(s: String) = s.filter {ch -> s.filter { it == ch }.count() == 1 }.toSortedSet().joinToString("")
}
약수 구하기
class Solution {
fun solution(n: Int) = (1..n).filter { n % it == 0 }
}
728x90