判定字符是否唯一
class Solution {
public:
bool isUnique(string astr) {
if(astr.size() > 26) return false;
int bit = 0;
for(auto e: astr)
{
int ch = e - 'a';
if(((bit>>ch) & 1) == 1) return false;
bit |= 1<< ch;
}
return true;
}
};
class Solution {
public:
bool isUnique(string astr) {
if(astr.size() > 26) return false;
int bit = 0;
for(auto e: astr)
{
int ch = e - 'a';
if(((bit>>ch) & 1) == 1) return false;
bit |= 1<< ch;
}
return true;
}
};