HashSet with is_subset

Pangram in Rust
use std::collections::HashSet;

pub fn is_pangram(sentence: &str) -> bool {
    let all: HashSet<char> = HashSet::from_iter("abcdefghijklmnopqrstuvwxyz".chars());
    let used: HashSet<char> = HashSet::from_iter(sentence.to_lowercase().chars());

In this approach a HashSet is made of the lowercase alphabet chars using the from_iter method, and another HashSet is made from the to_lowercase sentence chars.

The function returns if the alphabet HashSet is_subset of the sentence HashSet. If all of the letters in the alphabet are a subset of the letters in the sentence, then is_subset will return true.

22nd May 2024 · Found it useful?