Skip to content

Commit 39125fc

Browse files
committed
Add solution #500
1 parent 69fae15 commit 39125fc

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
448|[Find All Numbers Disappeared in an Array](./0448-find-all-numbers-disappeared-in-an-array.js)|Easy|
9090
451|[Sort Characters By Frequency](./0451-sort-characters-by-frequency.js)|Medium|
9191
459|[Repeated Substring Pattern](./0459-repeated-substring-pattern.js)|Easy|
92+
500|[Keyboard Row](./0500-keyboard-row.js)|Easy|
9293
541|[Reverse String II](./0541-reverse-string-ii.js)|Easy|
9394
551|[Student Attendance Record I](./0551-student-attendance-record-i.js)|Easy|
9495
565|[Array Nesting](./0565-array-nesting.js)|Medium|

solutions/0500-keyboard-row.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 500. Keyboard Row
3+
* https://leetcode.com/problems/keyboard-row/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of strings words, return the words that can be typed using letters
7+
* of the alphabet on only one row of American keyboard like the image below.
8+
*
9+
* In the American keyboard:
10+
* - the first row consists of the characters "qwertyuiop",
11+
* - the second row consists of the characters "asdfghjkl", and
12+
* - the third row consists of the characters "zxcvbnm".
13+
*/
14+
15+
/**
16+
* @param {string[]} words
17+
* @return {string[]}
18+
*/
19+
var findWords = function(words) {
20+
const rows = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'];
21+
return words.filter(word => rows.some(row => word.toLowerCase().split('').every(s => row.includes(s))));
22+
};

0 commit comments

Comments
 (0)