Created
February 8, 2019 07:08
-
-
Save viveknarang/225da07e113f20358354732ab97c1c58 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
class Solution { | |
public boolean isIsomorphic(String s, String t) { | |
if (s.length() != t.length()) { | |
return false; | |
} | |
Map<Character, Character> aMap = new HashMap<Character, Character>(); | |
Map<Character, Character> bMap = new HashMap<Character, Character>(); | |
for (int i = 0 ; i < s.length() ; i++) { | |
if (!aMap.containsKey(s.charAt(i))) { | |
aMap.put(s.charAt(i), t.charAt(i)); | |
bMap.put(t.charAt(i), s.charAt(i)); | |
} | |
} | |
if (aMap.size() != bMap.size()) { | |
return false; | |
} | |
for (int i = 0 ; i < s.length() ; i++) { | |
if (aMap.get(s.charAt(i)) != t.charAt(i)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment