#include <iostream>
#include<string>
using namespace std;
bool StringContain(string s1, string s2)
{
int hash = 0;
for (int i = 0; i<s1.length(); i++)
{
hash |= (1 << (s1[i] - 'A'));
}
cout<<hex<<hash<<endl;
for (int m = 0; m<s2.length(); m++)
{
if ((hash& (1 << (s2[m] - 'A'))) == 0)
{
return false;
}
}
return true;
}
int main()
{
string s1 = "";
string s2 = "";
cin >> s1;
cin >> s2;
if (StringContain(s1, s2))
cout << "true" << endl;
else
cout << "false" << endl;
return 0;
#include<string>
using namespace std;
bool StringContain(string s1, string s2)
{
int hash = 0;
for (int i = 0; i<s1.length(); i++)
{
hash |= (1 << (s1[i] - 'A'));
}
cout<<hex<<hash<<endl;
for (int m = 0; m<s2.length(); m++)
{
if ((hash& (1 << (s2[m] - 'A'))) == 0)
{
return false;
}
}
return true;
}
int main()
{
string s1 = "";
string s2 = "";
cin >> s1;
cin >> s2;
if (StringContain(s1, s2))
cout << "true" << endl;
else
cout << "false" << endl;
return 0;
}
时间复杂度O(m+n)
空间复杂度O(1)
hash |= (1 << (s1[i] - 'A'));这行代码什么意思(:有人能解析一下吗?