-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path500.py
62 lines (48 loc) · 1.6 KB
/
500.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Solution:
def findWords(self, words):
"""
:type words: List[str]
:rtype: List[str]
"""
firstline = ['q','w','e','r','t','y','u','i','o','p']
secondline = ['a','s','d','f','g','h','j','k','l']
thirdline = ['z','x','c','v','b','n','m']
result = []
for i in words:
right = 0
k=i.lower()
if k[0] in firstline :
flag = 1
if k[0] in secondline :
flag = 2
if k[0] in thirdline:
flag = 3
for j in range(1,len(k)):
if k[j] in firstline :
if flag==1:
right=0
continue
else:
right=1
break
if k[j] in secondline:
if flag==2:
right=0
continue
else:
right=1
break
if k[j] in thirdline:
if flag==3:
right=0
continue
else:
right=1
break
if right==0:
result.append(i)
return result
if __name__=='__main__':
sl=Solution()
words = ["Hello", "Alaska", "Dad", "Peace"]
sl.findWords(words)