标签:
//1.3 确定两串乱序同构
class Same {
public:
bool checkSam(string stringA, string stringB) {
// write code here
int lenA = stringA.size();
int lenB = stringB.size();
//如果长度都不同,则一定异构
if (lenA != lenB)
{
return false;
}
//用哈希表方法,以数组表示
int letters[256] = {0};
int i=0;
for (i=0; i<lenA; ++i)
{
int str = stringA[i];
++letters[str];
}
for (i=0; i<lenB; ++i)
{
int strB = stringB[i];
--letters[strB];
if (letters[strB] < 0)
return false;
}
return true;
}
};
标签:
原文地址:http://www.cnblogs.com/gxcdream/p/4912376.html