Back to Dashboard
Pangram
EasyProblem Statement
A pangram is a sentence where every letter of the English alphabet appears at least once.
Given a string sentence containing English letters (lower or upper-case), return true if sentence is a pangram, or false otherwise.
Note: The given sentence might contain other characters like digits or spaces, your solution should handle these too.
Examples
Example 1:
- Input:
sentence = "thequickbrownfoxjumpsoverthelazydog" - Output:
true
Example 2:
- Input:
sentence = "leetcode" - Output:
false
Approach 1:
O(n)
O(n)
class Solution {
public boolean checkIfPangram(String sentence) {
var set = new HashSet<Integer>();
for (var i = 0; i < sentence.length(); i ++) {
int ascii = sentence.charAt(i);
if (ascii >=65 && ascii <= 90) {
ascii += 32;
}
if (ascii >=97 && ascii <= 122) {
set.add(ascii);
}
}
System.out.println(set.size());
return set.size() == 26;
}
}