题目地址:
https://leetcode.com/problems/check-if-the-sentence-is-pangram/
给定一个小写英文字母的字符串,问其是否包含了所有的小写英文字母。
代码如下:
public class Solution {
public boolean checkIfPangram(String sentence) {
boolean[] exists = new boolean[26];
for (int i = 0; i < sentence.length(); i++) {
exists[sentence.charAt(i) - 'a'] = true;
}
for (boolean exist : exists) {
if (!exist) {
return false;
}
}
return true;
}
}
时空复杂度 O ( 1 ) O(1) O(1)。