Skip to content

Commit a9ed72d

Browse files
committed
Keyboard Row
1 parent 19fc86d commit a9ed72d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Source : https://leetcode.com/problems/keyboard-row/
2+
// Author : Han Zichi
3+
// Date : 2017-02-07
4+
5+
/**
6+
* @param {string[]} words
7+
* @return {string[]}
8+
*/
9+
var findWords = function(words) {
10+
let keys = [
11+
'qwertyuiop',
12+
'asdfghjkl',
13+
'zxcvbnm'
14+
];
15+
16+
let ans = [];
17+
18+
words.forEach(function(item) {
19+
let s = new Set();
20+
let word = item.toLowerCase();
21+
22+
for (let letter of word) {
23+
for (let i = 0; i < 3; i++)
24+
if (keys[i].indexOf(letter) !== -1) {
25+
s.add(i);
26+
break;
27+
}
28+
}
29+
30+
if (s.size === 1)
31+
ans.push(item);
32+
});
33+
34+
return ans;
35+
};

0 commit comments

Comments
 (0)