Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Real or Not? NLP with Disaster Tweets
- programmers
- 편스토랑 우승상품
- github
- gs25
- 백준
- SW Expert Academy
- 더현대서울 맛집
- ubuntu
- AI 경진대회
- ChatGPT
- Docker
- 프로그래머스
- 데이콘
- 코로나19
- Kaggle
- 금융문자분석경진대회
- leetcode
- Baekjoon
- PYTHON
- 파이썬
- 자연어처리
- hackerrank
- 맥북
- Git
- 캐치카페
- 편스토랑
- 프로그래머스 파이썬
- dacon
- 우분투
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 500. Keyboard Row (Python) 본문
728x90
반응형
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.
Example:
Input: ["Hello", "Alaska", "Dad", "Peace"]
Output: ["Alaska", "Dad"]
Note:
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
Solution
class Solution:
def findWords(self, words: List[str]) -> List[str]:
keyboard_dict = {"q":1, "Q":1, "w":1, "W":1, "e":1, "E":1, "r":1, "R":1, "t":1, "T":1, "y":1, "Y":1, "u":1, "U":1, "i":1, "I":1, "o":1, "O":1, "p":1, "P":1, "a":2, "A":2, "s":2, "S":2, "d":2, "D":2, "f":2, "F":2, "g":2, "G":2, "h":2, "H":2, "j":2, "J":2, "k":2, "K":2, "l":2, "L":2, "z":3, "Z":3, "x":3, "X":3, "c":3, "C":3, "v":3, "V":3, "b":3, "B":3, "n":3, "N":3, "m":3, "M":3}
answer = []
for word in words:
key_row_list = []
for char in word:
key_row_list.append(keyboard_dict[char])
key_row_list = list(set(key_row_list))
if len(key_row_list) == 1:
answer.append(word)
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1550. Three Consecutive Odds (Python) (0) | 2020.09.15 |
---|---|
[leetCode] 1365. How Many Numbers Are Smaller Than the Current Number (Python) (2) | 2020.09.14 |
[leetCode] 811. Subdomain Visit Count (Python) (0) | 2020.09.12 |
[leetCode] 1002. Find Common Characters (Python) (0) | 2020.09.12 |
[leetCode] 28. Implement strStr() (Python) (0) | 2020.09.10 |
Comments