Skip to content

Commit 87970c9

Browse files
authored
Create 205. Isomorphic Strings (#446)
2 parents ec4f94f + fae77dd commit 87970c9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

205. Isomorphic Strings

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool isIsomorphic(string s, string t) {
4+
vector<int> map1(128, 0); // Stores frequency of s
5+
vector<int> map2(128, 0); // Stores frequency of t
6+
7+
for(int i=0; i<s.length(); i++) {
8+
char s_ch = s[i];
9+
char t_ch = t[i];
10+
11+
if(map1[s_ch]==0 && map2[t_ch]==0) {
12+
map1[s_ch] = t_ch;
13+
map2[t_ch] = s_ch;
14+
}
15+
else if(map1[s_ch] != t_ch || map2[t_ch] != s_ch) {
16+
return false;
17+
}
18+
}
19+
return true;
20+
}
21+
};

0 commit comments

Comments
 (0)