-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path205.cpp
More file actions
39 lines (38 loc) · 701 Bytes
/
205.cpp
File metadata and controls
39 lines (38 loc) · 701 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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char,int> stoi;
map<char,int> ttoi;
int cnt=0;
for(int i=0;i<s.size();i++)
{
if(stoi.find(s[i])==stoi.end() )//s没有时
{
if(ttoi.find(t[i])==ttoi.end()) //t没有时
{
stoi[s[i]]=cnt;
ttoi[t[i]]=cnt;
cnt++;
}
else return false;
}
else if(ttoi.find(t[i])==ttoi.end())
return false; //s有,t没有
else{ //都有时
if(stoi[s[i]]!=ttoi[t[i]])
return false;
}
}
return true;
}
};