参考链接
- https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram/
题目描述
全字母句 指包含英语字母表中每个字母至少一次的句子。
给你一个仅由小写英文字母组成的字符串 sentence ,请你判断 sentence 是否为 全字母句 。
如果是,返回 true ;否则,返回 false 。
解题思路
题目比较简单,根据提示句子只包含小写字母,连是否为小写字母的判定都省了。直接使用集合,把字符串的每个字符都放入集合,因为集合不包含相同字符,所以最后看集合大小是不是26即可。
代码
class Solution {
public:
bool checkIfPangram(string sentence) {
unordered_set<char> current;
for (int i = 0; i < sentence.size(); i ++)
{
current.insert(sentence[i]);
}
return current.size() == 26 ? true : false;
}
};