Skip to content

Commit d278f0f

Browse files
authored
Merge pull request #1602 from MHamiid/patch-16
Create 205-Isomorphic-Strings.cpp
2 parents 6a4e00c + cf8b425 commit d278f0f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cpp/205-Isomorphic-Strings.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
bool isIsomorphic(string s, string t) {
4+
unordered_map<char, char> STMap, TSMap;
5+
6+
for(size_t i = 0; i < s.size(); i++)
7+
{
8+
// (STMap[s[i]] != 0) ===> If the char is not in the map
9+
if((STMap[s[i]] != 0 && STMap[s[i]] != t[i]) || (TSMap[t[i]] != 0 && TSMap[t[i]] != s[i]))
10+
{
11+
return false;
12+
}
13+
14+
STMap[s[i]] = t[i];
15+
TSMap[t[i]] = s[i];
16+
}
17+
18+
return true;
19+
}
20+
};

0 commit comments

Comments
 (0)