給你乙個字串陣列 words ,只返回可以使用在 美式鍵盤 同一行的字母列印出來的單詞。鍵盤如下圖所示。
美式鍵盤 中:
第一行由字元 "qwertyuiop" 組成。
第二行由字元 "asdfghjkl" 組成。
第三行由字元 "zxcvbnm" 組成。
示例 1:
輸入:words = [「hello」,「alaska」,「dad」,「peace」]
輸出:[「alaska」,「dad」]
示例 2:
輸入:words = [「omk」]
輸出:
示例 3:
輸入:words = [「adsdf」,「sfd」]
輸出:[「adsdf」,「sfd」]
1 <= words.length <= 20
1 <= words[i].length <= 100
words[i] 由英文本母(小寫和大寫字母)組成
class
solution
:def
findwords
(self, words)
: l1 =
["q"
,"w"
,"e"
,"r"
,"t"
,"y"
,"u"
,"i"
,"o"
,"p"
,"q"
,"w"
,"e"
,"r"
,"t"
,"y"
,"u"
,"i"
,"o"
,"p"
] l2 =
["a"
,"s"
,"d"
,"f"
,"g"
,"h"
,"j"
,"k"
,"l"
,"a"
,"s"
,"d"
,"f"
,"g"
,"h"
,"j"
,"k"
,"l"
] l3 =
["z"
,"x"
,"c"
,"v"
,"b"
,"n"
,"m"
,"z"
,"x"
,"c"
,"v"
,"b"
,"n"
,"m"
] tag =
res =
for i in words:
s_len =
0if i[0]
in l1:
tag = l1
elif i[0]
in l2:
tag = l2
else
: tag = l3
for j in i:
if j in tag:
s_len +=
1if s_len ==
len(i)
:return res
每日一題 1
題目詳情 peter喜歡玩數字遊戲,但數獨這樣的遊戲對他來說太簡單了,於是他準備玩乙個難的遊戲。遊戲規則是在乙個n n的 裡填數,規則 對於每個輸入的n,從左上角開始,總是以對角線為起點,先橫著填,再豎著填。這裡給了一些樣例,請在樣例中找到規律並把這個n n的 列印出來吧。輸入描述 多組測試資料 資...
每日一題2018 3 21
leetcode 2 模擬十進位制運算考察單鏈表基本操作。題無難點,個人基礎需要提高。definition for singly linked list.struct listnode class solution while p while q if shi val s next null ret...
每日一題2018 3 22
leetcode 03 最長不重複子串 第一反應就是動態規劃。看到了網上的方法一。直接把問題簡化為找兩個重複字元間的最長距離,太巧妙了!class solution if i idx max locs s i i return max ling老師的方法二 仍舊轉化為動態規劃,但是為節省空間不再開個...