스트링2개 각각 해시맵에 넣고 두개 비교해서 같으면 true 다르면 false 리턴
정답
class Solution {
fun isAnagram(s: String, t: String): Boolean {
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
}
return sHashMap==tHashMap
}
}
'알고리즘' 카테고리의 다른 글
릿코드 661. Image Smoother 코틀린 (0) | 2023.12.19 |
---|---|
릿코드 1913. Maximum Product Difference Between Two Pairs 코틀린 (0) | 2023.12.18 |
릿코드 1436. Destination City 코틀린 (0) | 2023.12.15 |
릿코드 2482. Difference Between Ones and Zeros in Row and Column 코틀린 (0) | 2023.12.14 |
릿코드 1582. Special Positions in a Binary Matrix 코틀린 (0) | 2023.12.13 |