Back to course home
0% completed
Vote For New Content
Valid solution without using a hashmap
Nabeel Keblawi
Sep 4, 2024
What I did was first convert the sentence to lower case, then declared an alphabet string to loop through it and search for each character in the sentence.
Since we're looking for pangrams that have ALL the letters in the alphabet, if the "char not in sentence_lower" is ever found true, then abort the function by returning False. If the loop completes without executing the conditional block, then return True.
More than one way to skin a cat...
class Solution: def checkIfPangram(self, sentence): sentence_lower = sentence.lower() alphabet = "abcdefghijklmnopqrstuvwxyz" for char in alphabet: if char not in sentence_lower: return False return True
1
0
Comments
Comments
Nabeel Keblawia year ago
This is O(n) for both time and space complexity, btw
Ashaun Thomasa year ago
Straightforward solution
On this page
Problem Statement
Solution
Code
Time Complexity
Space Complexity
Conclusion