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:
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence contains at least one of every letter of the English alphabet.
Approach
C++
#include <bits/stdc++.h>using namespace std;bool checkIfPangram(string sentence){int freq[26] = {0};for (int i = 0; i < sentence.size(); i++){freq[sentence[i] - 'a']++;}for (int i = 0; i < 26; i++){if (freq[i] == 0)return false;}return true;}int main(){string sentence = "thequickbrownfoxjumpsoverthelazydog";if (checkIfPangram(sentence))cout << "true\n";elsecout << "false\n";return 0;}
No comments:
Post a Comment