Skip to content

Commit e2e5c97

Browse files
authored
Create 0205-Isomorphic-Strings.cpp
1 parent 1a8aaf7 commit e2e5c97

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cpp/0205-Isomorphic-Strings.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*Given two strings s and t, determine if they are isomorphic.
2+
3+
Two strings s and t are isomorphic if the characters in s can be replaced to get t.
4+
5+
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
6+
7+
*/
8+
class Solution {
9+
public:
10+
bool isIsomorphic(string s, string t) {
11+
unordered_map<char,vector<int>>m1;
12+
unordered_map<char,vector<int>>m2;
13+
for(int i=0;i<s.length();i++){
14+
m1[s[i]].push_back(i);
15+
m2[t[i]].push_back(i);
16+
17+
if(m1[s[i]]!=m2[t[i]])
18+
return false;
19+
}
20+
return true;
21+
22+
}
23+
};

0 commit comments

Comments
 (0)