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 1
1
/**
2
2
* Question Link: https://leetcode.com/problems/keyboard-row/
3
3
* Primary idea: Use filter to determine the word is subset or not.
4
- *
4
+ *
5
5
* Note: You can also use intersect() or union() functions to solve this problem.
6
6
*
7
7
* Time Complexity: O(nm), Space Complexity: O(n)
8
8
*
9
9
*/
10
10
11
11
class 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 "
14
14
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
+ }
17
18
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
22
22
}
23
- }
23
+ }
You can’t perform that action at this time.
0 commit comments