Check if the Sentence Is Pangram LeetCode Solution - The Coding Shala

Home >> LeetCode >> Check if the Sentence is Pangram

 In this post, we will learn how to solve LeetCode's Check if the Sentence Is Pangram Problem and will implement its solution in Java.

Check if the Sentence Is Pangram Problem

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 the 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

Practice this problem on LeetCode.

LeetCode - Check if the Sentence Is Pangram Java Solution

Approach 1

As we know HashSet contains only unique values. So here we can use a Character HashSet and then check the size of the set if it is 26 then the string is a pangram.

Java Program: 

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


Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to Create a Simple Calculator - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala

Java Program to Find GCD or HCF of Two Numbers - The Coding Shala