1832. Check if the Sentence Is Pangram

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.

1832. Check if the Sentence Is Pangram
struct Solution;

use std::collections::HashSet;

impl Solution {
    fn check_if_pangram(sentence: String) -> bool {
        let mut hs: HashSet<char> = HashSet::new();
        for c in sentence.chars() {
            hs.insert(c);
        }
        hs.len() == 26
    }
}

#[test]
fn test() {
    let sentence = "thequickbrownfoxjumpsoverthelazydog".to_string();
    let res = true;
    assert_eq!(Solution::check_if_pangram(sentence), res);
    let sentence = "leetcode".to_string();
    let res = false;
    assert_eq!(Solution::check_if_pangram(sentence), res);
}