[LeetCode] Check if the Sentence Is Pangram

1832. Check if the Sentence Is Pangram

A pangram is a sentence where every letter of the English alphabet appears at least once.

Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
bool checkIfPangram(string sentence) {
const int pangram = (1<<26) - 1;
int res = 0;
for(auto& c : sentence) {
res |= (1<<(c-'a'));
if(!(res ^ pangram)) return true;
}

return !(pangram ^ res);
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2021/04/18/PS/LeetCode/check-if-the-sentence-is-pangram/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.