[LeetCode]#1832. Check if the Sentence Is Pangram
Jul 18, 2021
Environment: Python 3.8
Key technique: Counter
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.
Analysis:
- if string length is less than 26, return false
- Use counter. if key length is less than 26, return false
- else case, return True
Solution:
from collections import Counter
class Solution:
def checkIfPangram(self, sentence):
if len(sentence)<26:
return False
if len(Counter(sentence).keys())<26:
return False
else:
return True
Submissions:
Reference: