相比一般的设置数组hash,消耗更少的空间
class Solution {
public:
bool isUnique(string s) {
int x = 0;
for(char c : s) {
if(x & (1 << (c - 'a'))) { // c - 'a':将字符转换为0-25的数字
return false;
} else {
x |= 1 << (c - 'a');
}
}
return true;
}
};