-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path205. Isomorphic Strings.cpp
More file actions
52 lines (49 loc) · 1.19 KB
/
205. Isomorphic Strings.cpp
File metadata and controls
52 lines (49 loc) · 1.19 KB
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
49
50
51
52
#include <vector>
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
bool isIsomorphic(string s, string t) {
if(s.length()!=t.length()) return false;
vector<int> s1,t1;
int s2=0,t2=0,i,j;
for(i=0;i<s.length();i++){
for(j=0;j<i;j++){
if(s[i]==s[j]){
s1.push_back(s1[j]);
break;
}
}
if(s1.size()<i+1){
s1.push_back(s2++);
}
}
for(i=0;i<t.length();i++){
for(j=0;j<i;j++){
if(t[i]==t[j]){
t1.push_back(s1[j]);
break;
}
}
if(t1.size()<i+1){
t1.push_back(t2++);
}
}
for(i=0;i<s1.size();i++){
cout<<s1[i]<<' ';
}cout<<endl;
for(i=0;i<t1.size();i++){
cout<<t1[i]<<' ';
}cout<<endl;
for(i=0;i<s1.size();i++){
if(s1[i]!=t1[i])
return false;
}
return true;
}
};
int main(void){
Solution my;
cout<<my.isIsomorphic("addccccb","eggddddf");
}