forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0205.cpp
32 lines (31 loc) · 768 Bytes
/
0205.cpp
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
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
bool isIsomorphic(string s, string t)
{
unordered_map<char, int> str_map1;
unordered_map<char, int> str_map2;
if (s.size() != t.size()) return false;
for (int i = 0; i < s.size(); ++i)
{
if (str_map1[s[i]] != str_map2[t[i]])
{
return false;
}
str_map1[s[i]] = str_map2[t[i]] = i + 1;
}
return true;
}
};
int main()
{
string pattern = "egg";
string str = "add";
cout << Solution().isIsomorphic(pattern, str) << endl;
return 0;
}