23 lines
No EOL
655 B
Kotlin
23 lines
No EOL
655 B
Kotlin
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"))
|
|
|
|
}
|
|
} |