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.*
LeetCode Problem - 1832
class Solution {
public boolean checkIfPangram(String sentence) {
// Initialize a boolean variable to true
boolean check = true;
// Loop through ASCII values of lowercase letters (97 to 122)
for (int i=97; i<123; i++){
// Reset check to true for each iteration
check = true;
// Loop through characters in the sentence
for(int j=0; j<sentence.length(); j++){
// If the ASCII value matches a character in the sentence
if(i == sentence.codePointAt(j)){
// Set check to false and break out of the loop
check = false;
break;
}
}
// If the character is missing from the sentence, return false
if(check) return false;
}
// If all characters are present, return true
return true;
}
}