-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsomorphicStrings.cc
52 lines (39 loc) · 943 Bytes
/
IsomorphicStrings.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "leet.h"
#include <algorithm>
#include <cstring>
class Solution{
public:
bool isIsomorphic(string s, string t) {
size_t len = s.length();
if (len != t.length()) {
return false;
}
char map[128];
bool vst[128];
std::memset(map, 0, sizeof map);
std::memset(vst, false, sizeof vst);
for (size_t i = 0; i < len; ++i) {
int chs = s[i];
int cht = t[i];
if (vst[cht]) {
if (map[chs] != cht) {
return false;
}
} else if (map[chs]) {
return false;
} else {
vst[cht] = true;
map[chs] = cht;
}
}
return true;
}
};
int main(){
Solution slu;
string s, t;
while (cin >> s >> t) {
cout << slu.isIsomorphic(s, t) << endl;
}
return 0;
}