1
2
3
4
5
6
7
8
9
class Solution {
public boolean checkIfPangram(String sentence) {
int count = 0;
for (char letter : sentence.toCharArray()) {
count |= (1 << ((int) (letter - 'a')));
}
return count == ((1 << 26) - 1);
}
}

Bit Manipulation.
用一个int中的bits来存每个letter是否出现. bit 0存a, bit 1存b…

最后看这个int是否等于1 << 26 再减去1.

时间复杂度: O(n)
空间复杂度: O(1)