https://leetcode.com/problems/isomorphic-strings Easy

Решение

class Solution {
    fun isIsomorphic(s: String, t: String): Boolean {
        val m1 = IntArray(256) { -1 }
        val m2 = IntArray(256) { -1 }
        var i = 0
        val n = s.length
        while (i < n) {
            val a = s[i].code
            val b = t[i].code
            val x = m1[a]
            val y = m2[b]
            if (x == -1 && y == -1) {
                m1[a] = b
                m2[b] = a
            } else if (x != b || y != a) {
                return false
            }
            i++
        }
        return true
    }
}