Description
Difficulty: Easy
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard.
Example 1:
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
先创建三个字符串,分别包含键盘上三行的字母(大小写),然后遍历每个单词后续字母是否与第一个字母在同一行;注意发现不同时跳过当前单词节省时间。
|
|
近期评论