Skip to content

Commit 6863436

Browse files
authored
Create valid-word.py
1 parent e6457ae commit 6863436

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Python/valid-word.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# string
5+
class Solution(object):
6+
def isValid(self, word):
7+
"""
8+
:type word: str
9+
:rtype: bool
10+
"""
11+
VOWELS = "aeiou"
12+
13+
if len(word) < 3:
14+
return False
15+
vowel = consonant = False
16+
for x in word:
17+
if x.isalpha():
18+
if x.lower() in VOWELS:
19+
vowel = True
20+
else:
21+
consonant = True
22+
elif not x.isdigit():
23+
return False
24+
return vowel and consonant

0 commit comments

Comments
 (0)