Created
August 13, 2018 15:17
-
-
Save waynejo/061af937141c26ebafaf827b48be38ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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