-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path205.cpp
More file actions
38 lines (35 loc) · 853 Bytes
/
205.cpp
File metadata and controls
38 lines (35 loc) · 853 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
//
// 205.cpp
// LeetCode
//
// Created by 张佐玮 on 15/8/3.
// Copyright (c) 2015年 JarvisZhang. All rights reserved.
//
// Title: Isomorphic Strings
//
#include <iostream>
using namespace std;
class Solution {
public:
bool isIsomorphic(string s, string t) {
char sToTHash[256] = {0}, tToSHash[256] = {0};
if (s.size() != t.size()) {
return false;
}
for (int i = 0; i < s.size(); i++) {
if (sToTHash[s[i]] == 0) {
sToTHash[s[i]] = t[i];
}
else if (sToTHash[s[i]] != t[i]) {
return false;
}
if (tToSHash[t[i]] == 0) {
tToSHash[t[i]] = s[i];
}
else if (tToSHash[t[i]] != s[i]) {
return false;
}
}
return true;
}
};