Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created August 13, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynejo/061af937141c26ebafaf827b48be38ad to your computer and use it in GitHub Desktop.
Save waynejo/061af937141c26ebafaf827b48be38ad to your computer and use it in GitHub Desktop.
func isIsomorphic(s string, t string) bool {
if len(s) != len(t) {
return false
}
var pairs = make(map[uint8]uint8)
var reversePairs = make(map[uint8]uint8)
for idx := range s {
if v, ok := pairs[s[idx]]; ok {
if v != t[idx] {
return false
}
} else {
if _, ok := reversePairs[t[idx]]; ok {
return false
}
pairs[s[idx]] = t[idx]
reversePairs[t[idx]] = s[idx]
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment