-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode-205.cpp
More file actions
28 lines (25 loc) · 823 Bytes
/
LeetCode-205.cpp
File metadata and controls
28 lines (25 loc) · 823 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
/*************************************************************************
> File Name: LeetCode-205.cpp
> Author: ltw
> Mail: 3245849061@qq.com
> Created Time: Thu 21 May 2020 06:30:35 PM CST
************************************************************************/
#include <iostream>
using namespace std;
class Solution {
public:
bool isIsomorphic(string s, string t) {
if (s.size() - t.size()) return false;
int s_code[256] = {0}, t_code[256] = {0};
for (int i = 0; s[i]; i++) {
if (s_code[s[i]] == 0) {
if (t_code[t[i]]) return false;
s_code[s[i]] = t[i];
t_code[t[i]] = s[i];
}
int val = s_code[s[i]];
if (val - t[i]) return false;
}
return true;
}
};