Check Isomorphic Strings
STRING
Problem
Given two strings str1
and str2
, return true
if they are isomorphic.
Two strings are isomorphic if the characters in str1
can be replaced to get str2
, ensuring that no two characters map to the same character and each character maps to itself.
Examples
areIsomorphic("bad", "tog") // returns true // Why? Each letter from 'bad' can be reshaped to form 'tog'. areIsomorphic("cat", "car") // returns true // Why? 't' can be changed to 'r' and create an isomorphic sand. areIsomorphic("ball", "teet") // returns false // Why? Letters in 'ball' cannot be reshaped to form 'teet'.
Loading...