KtLeetcode/src/Test205.kt

23 lines
655 B
Kotlin
Raw Normal View History

2024-11-06 05:43:21 +01:00
class Test205 {
class Solution {
fun isIsomorphic(s: String, t: String): Boolean {
val f = mutableMapOf<Char,Char>()
val fp = mutableMapOf<Char,Char>()
for (i in s.indices){
if (f.containsKey(s[i]) || fp.containsKey(t[i])){
if (t[i] != f[s[i]] || s[i] != fp[t[i]]){
return false
}
}else{
f[s[i]] = t[i]
fp[t[i]] = s[i]
}
}
return true
}
}
fun test(){
println(Solution().isIsomorphic("badc","baba"))
}
}