◻️1832. Check if the Sentence Is Pangram (easy)

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

Solutions

Normal

Runtime 4 ms Memory 7.99 MB

// from gfg
class Solution {
public:
    bool checkIfPangram(string sentence) {
        int n = sentence.length();
        int index;
        vector<bool> mark(26, false);
        for(int i=0; i<n; i++){
            if('A' <= sentence[i] && sentence[i] <= 'Z'){
                index=sentence[i] - 'A';
            }
            else if('a' <= sentence[i] && sentence[i] <= 'z'){
                index=sentence[i] - 'a';
            }
            else
                continue;
            mark[index] = true;
        }

        for(int i=0; i<26; i++){
            if(mark[i] == false){
                return (false);
            }
        }
        return (true);
    }
};

Optimised

Runtime 0 ms Memory 8.12 MB

Last updated