Skip to content

Commit 9251282

Browse files
authored
Merge pull request soapyigu#283 from peacemoon/fix_keyboardrow
Fix solution for KeyboardRow
2 parents 55bdfbb + 58a723e commit 9251282

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

String/KeyboardRow.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
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

1111
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"
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+
}

0 commit comments

Comments
 (0)