-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheckIfPangram.py
More file actions
33 lines (27 loc) · 957 Bytes
/
CheckIfPangram.py
File metadata and controls
33 lines (27 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'''
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
'''
class Solution:
def checkIfPangram(self, sentence: str) -> bool:
# naive approach - 1
# freq = {}
# for i in sentence:
# freq[i] = freq.get(i, 0) + 1
# if len(freq) == 26: return True
# return False
# optimized approach - 2
occurred = 0
for i in sentence:
temp = ord(i) - ord('a')
occurred |= (1 << temp)
if occurred == (1 << 26) - 1:
return True
return False