Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java approach 2 #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion HashMap/Isomorphic Strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Solution {



/****************************************** C++ ******************************************/
/****************************************** JAVA ******************************************/
//T.C : O(n)
//S.C : O(1) -> Take array of size 256 to handle all ASCII characters instead of taking map
class Solution {
Expand All @@ -61,3 +61,25 @@ class Solution {
return true;
}
}






// Approach 2(HashMap approach ) :-
class Solution {
public boolean isIsomorphic(String s, String t) {
HashMap<Character, Integer> hm1 = new HashMap<>();
HashMap<Character, Integer> hm2 = new HashMap<>();

for (int i = 0; i < s.length(); i++)
if (hm1.put(s.charAt(i), i) != hm2.put(t.charAt(i), i))
return false;

return true;
}
}