Formatted question description: https://leetcode.ca/all/1832.html

1832. Check if the Sentence Is Pangram

Level

Easy

Description

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.

Example 1:

Input: sentence = “thequickbrownfoxjumpsoverthelazydog”

Output: true

Explanation: sentence contains at least one of every letter of the English alphabet.

Example 2:

Input: sentence = “leetcode”

Output: false

Constraints:

  • 1 <= sentence.length <= 1000
  • sentence consists of lowercase English letters.

Solution

Use a set to store all the lowercase letters that exist in sentence. Return true if and only if the set’s size is 26.

class Solution {
    public boolean checkIfPangram(String sentence) {
        Set<Character> set = new HashSet<Character>();
        int length = sentence.length();
        for (int i = 0; i < length; i++) {
            char c = sentence.charAt(i);
            if (c >= 'a' && c <= 'z')
                set.add(c);
        }
        return set.size() == 26;
    }
}

All Problems

All Solutions