Skip to content

Instantly share code, notes, and snippets.

@ebanner
Created May 21, 2024 21:32
Show Gist options
  • Save ebanner/29e59e0eef53319636297dd7cbab550e to your computer and use it in GitHub Desktop.
Save ebanner/29e59e0eef53319636297dd7cbab550e to your computer and use it in GitHub Desktop.
# @param {String} s
# @param {String} t
# @return {Boolean}
def is_isomorphic(s, t)
numeric_s = convert_to_numeric(s)
numeric_t = convert_to_numeric(t)
numeric_s == numeric_t
# More explicit version
# isomorphic = numeric_s == numeric_t
# isomorphic
end
# def isomorphic?(numeric_s, numeric_t)
# numeric_s == numeric_t
# end
def convert_to_numeric(str)
map = {}
counter = 1
list = []
str.each_char do |c|
unless map.has_key?(c)
map[c] = counter
counter += 1
end
list << map[c]
end
list
end
# puts is_isomorphic("egg", "add")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment