1832. 判断句子是否为全字母句 - 力扣(LeetCode)
数组哈希
包含字母表所有字母
a-z都可以映射ascii表对应的值,且大小不超过一个字节,也就是255
class Solution {
public:
bool checkIfPangram(string sentence) {
int hash[256];
memset(hash,0,sizeof(hash));
for(int i=0;i<sentence.size();++i)
{
++hash[sentence[i]]; //技术自增
}
for(int i='a';i<='z';++i)
{
if(!hash[i])return false;//如果没有a-z没有出现过一次说明 不合法
}
return true;
}
};```