문자열2개를 해시맵에 넣은다음,t에서 s를 빼고 남은수리턴
정답
class Solution {
fun minSteps(s: String, t: String): Int {
val sHashMap = hashMapOf<Char, Int>()
val tHashMap = hashMapOf<Char, Int>()
for (i in s){
sHashMap[i]=sHashMap[i]?.plus(1)?:1
}
for (i in t){
tHashMap[i]=tHashMap[i]?.plus(1)?:1
}
for ((key,value) in sHashMap){
if (tHashMap[key]==null){
continue
}
tHashMap[key]=tHashMap[key]!!- value
}
return tHashMap.filter { it.value>0 }.values.sum()
}
}
'알고리즘' 카테고리의 다른 글
릿코드 2225. Find Players With Zero or One Losses 코틀린 (0) | 2024.01.15 |
---|---|
릿코드 1657. Determine if Two Strings Are Close 코틀린 (1) | 2024.01.14 |
릿코드 1704. Determine if String Halves Are Alike 코틀린 (0) | 2024.01.12 |
릿코드 1026. Maximum Difference Between Node and Ancestor 코틀린 (0) | 2024.01.11 |
릿코드 872. Leaf-Similar Trees 코틀린 (0) | 2024.01.09 |