Keyboard Row – LeetCode 500
Problem
Description
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”]
Answer
Original
Code
1 | class Solution { |
思路
简单的检测单词是不是都在同一行。时间复杂度$O(n)$,空间复杂度$O(1)$。
耗时$3$ ms,排名$38.03\%$
Better
思路
还没看到更好的思路。