LeetCode 205 Isomorphic Strings
#include <string>
using namespace std;
class Solution {
public:
bool isIsomorphic(string s, string t) {
char s_t[128] = { 0 };
char t_s[128] = { 0 };
for (int i = 0; i < s.length(); i++){
if (s_t[s[i]] == 0 && t_s[t[i]] == 0){
s_t[s[i]] = t[i];
t_s[t[i]] = s[i];
}
else if (s_t[s[i]] != t[i] || t_s[t[i]] != s[i])
return false;
}
return true;
}
};
/*class Solution {
public:
bool isIsomorphic(string s, string t) {
if (s.size() != t.size())
return false;
int m1[256] = { 0 };
int m2[256] = { 0 };
for (int i = 0; i<s.size(); ++i) {
if (m1[s[i]] != m2[t[i]])
return false;
m1[s[i]] = i + 1;
m2[t[i]] = i + 1;
}
return true;
}leetcode上的一个6ms的实现方法,用数字~
};*/