LeetCode 500. Keyboard Row
题目描述:
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 1:
1
2
3 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.
判断每个字母在键盘上位于哪一行,可以用Hash表来保存每个字母所对应的行,也可以每次都搜索一次,因为数据量都很小所以性能差距很小。
Hash表:
1 | class Solution { |
搜索:
1 | class Solution { |