lc-go/solutions/2/q205/solution.go

27 lines
496 B
Go

// Package q205 implements a solution for https://leetcode.com/problems/isomorphic-strings/
package q205
func isIsomorphic(s string, t string) bool {
if len(s) != len(t) {
return false
}
ab := make(map[byte]byte, 256)
ba := make(map[byte]byte, 256)
for i := range len(s) {
if b, ok := ab[s[i]]; ok {
if t[i] != b {
return false
}
} else {
if _, ok := ba[t[i]]; ok {
return false
}
ab[s[i]] = t[i]
ba[t[i]] = s[i]
}
}
return true
}
var _ = isIsomorphic