Skip to content

Create 205. Isomorphic Strings #446

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

Merged
merged 1 commit into from
Apr 2, 2024
Merged
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
21 changes: 21 additions & 0 deletions 205. Isomorphic Strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
bool isIsomorphic(string s, string t) {
vector<int> map1(128, 0); // Stores frequency of s
vector<int> map2(128, 0); // Stores frequency of t

for(int i=0; i<s.length(); i++) {
char s_ch = s[i];
char t_ch = t[i];

if(map1[s_ch]==0 && map2[t_ch]==0) {
map1[s_ch] = t_ch;
map2[t_ch] = s_ch;
}
else if(map1[s_ch] != t_ch || map2[t_ch] != s_ch) {
return false;
}
}
return true;
}
};
Loading