File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change 11/**
22 * Question Link: https://leetcode.com/problems/keyboard-row/
33 * Primary idea: Use filter to determine the word is subset or not.
4- *
4+ *
55 * Note: You can also use intersect() or union() functions to solve this problem.
66 *
77 * Time Complexity: O(nm), Space Complexity: O(n)
88 *
99 */
1010
1111class KeyboardRow {
12- func findWords( _ words: [ String ] ) -> [ String ] {
13- let rowOne = " qwertyuiop " , rowTwo = " asdfghjkl " , rowThree = " zxcvbnm "
12+ func findWords( _ words: [ String ] ) -> [ String ] {
13+ let rowOne = " qwertyuiop " , rowTwo = " asdfghjkl " , rowThree = " zxcvbnm "
1414
15- return words. filter { word in rowOne. contains ( word) || rowTwo. contains ( word) || rowThree. contains ( word) }
16- }
15+ return words. filter { word in rowOne. contains ( word. lowercased ( ) ) || rowTwo. contains ( word. lowercased ( ) ) || rowThree. contains ( word. lowercased ( ) ) }
16+ }
17+ }
1718
18- extension String {
19- func contains( _ word: String ) -> Bool {
20- return word. filter { c in !self . contains ( c) } . characters. count == 0
21- }
19+ extension String {
20+ func contains( _ word: String ) -> Bool {
21+ return word. filter { c in !self . contains ( c) } . count == 0
2222 }
23- }
23+ }
You can’t perform that action at this time.
0 commit comments