-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path500.py
More file actions
executable file
·35 lines (35 loc) · 1.21 KB
/
500.py
File metadata and controls
executable file
·35 lines (35 loc) · 1.21 KB
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
34
35
class Solution(object):
def findWords(self, words):
"""
:type words: List[str]
:rtype: List[str]
"""
First = ['Q','W','E','R','T','Y','U','I','O','P']
SEC = ['A','S','D','F','G','H','J','K','L']
LAST= ['Z','X','C','V','B','N','M']
answer = []
for word in words:
now = -1
answer_flag = True
for chr in word:
if (now == - 1):
if ((chr.upper()) in First):
now = 1
if ((chr.upper()) in SEC):
now = 2
if ((chr.upper()) in LAST):
now = 3
else:
flag = False
if ((chr.upper()) in First and now == 1):
flag = True
if ((chr.upper()) in SEC and now == 2):
flag = True
if ((chr.upper()) in LAST and now == 3):
flag = True
if (flag == False):
answer_flag = False
break
if (answer_flag):
answer.append(word)
return answer