In this tutorial, we will learn about isomorphic strings and we will find if the string is isomorphic or not.
Two strings s1 and s2 can be called isomorphic if we can map all the characters of s1 to all the characters of s2.
Like for Example, s1="aab" and s2="xxy"
Here, we can say a->x and b->y i.e a is mapped with x, and b is mapped with y.
We can use maps from STL to map these strings together if all the characters are mapped then we return true else we return false.
1. If the length of both strings is not the same return false.
2. If there is a character that appears in s1 then it can not be present in s2.
3. If a character is a new mark that character has visited and it should not repeat itself in another string if it does return false.
4. Store the currently mapped charachters.
5. If everything is mapped then return true.
Submitted by srijan bharadwaj (srijan77)
Download packets of source code on Coders Packet
Comments