File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 89
89
448|[ Find All Numbers Disappeared in an Array] ( ./0448-find-all-numbers-disappeared-in-an-array.js ) |Easy|
90
90
451|[ Sort Characters By Frequency] ( ./0451-sort-characters-by-frequency.js ) |Medium|
91
91
459|[ Repeated Substring Pattern] ( ./0459-repeated-substring-pattern.js ) |Easy|
92
+ 500|[ Keyboard Row] ( ./0500-keyboard-row.js ) |Easy|
92
93
541|[ Reverse String II] ( ./0541-reverse-string-ii.js ) |Easy|
93
94
551|[ Student Attendance Record I] ( ./0551-student-attendance-record-i.js ) |Easy|
94
95
565|[ Array Nesting] ( ./0565-array-nesting.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments