-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.hpp
More file actions
48 lines (35 loc) · 828 Bytes
/
Solution.hpp
File metadata and controls
48 lines (35 loc) · 828 Bytes
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
#include <string>
#include <string.h>
using std::string;
class Solution {
public:
bool isIsomorphic(string s, string t) {
int sSize = s.size();
int tSize = t.size();
if(sSize != tSize)
{
return false;
}
char charMap[256];
char mapped[256];
memset(charMap, '\0', sizeof(charMap));
memset(mapped, 0, sizeof(mapped));
for(int index = 0; index < sSize; ++index)
{
if(charMap[s[index]] == '\0')
{
if(mapped[t[index]])
{
return false;
}
charMap[s[index]] = t[index];
mapped[t[index]] = 1;
}
else if(charMap[s[index]] != t[index])
{
return false;
}
}
return true;
}
};