We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ec4f94f + fae77dd commit 87970c9Copy full SHA for 87970c9
205. Isomorphic Strings
@@ -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