-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path205.cpp
More file actions
34 lines (28 loc) · 800 Bytes
/
205.cpp
File metadata and controls
34 lines (28 loc) · 800 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
/*
* Written by Nitin Kumar Maharana
* nitin.maharana@gmail.com
*/
class Solution {
int len;
public:
bool isIsomorphic(string s, string t) {
if(s.length() != t.length())
return false;
char smemory[256], tmemory[256];
len = s.length();
memset(smemory, 0, sizeof(smemory));
memset(tmemory, 0, sizeof(tmemory));
for(int i = 0; i < len; i++)
{
if(smemory[s[i]] == 0)
smemory[s[i]] = t[i];
else if(smemory[s[i]] != t[i])
return false;
if(tmemory[t[i]] == 0)
tmemory[t[i]] = s[i];
else if(tmemory[t[i]] != s[i])
return false;
}
return true;
}
};