diff --git a/String/KeyboardRow.swift b/String/KeyboardRow.swift index 5de42c82..8e81fa3c 100644 --- a/String/KeyboardRow.swift +++ b/String/KeyboardRow.swift @@ -1,7 +1,7 @@ /** * Question Link: https://leetcode.com/problems/keyboard-row/ * Primary idea: Use filter to determine the word is subset or not. - * + * * Note: You can also use intersect() or union() functions to solve this problem. * * Time Complexity: O(nm), Space Complexity: O(n) @@ -9,15 +9,15 @@ */ class KeyboardRow { - func findWords(_ words: [String]) -> [String] { - let rowOne = "qwertyuiop", rowTwo = "asdfghjkl", rowThree = "zxcvbnm" + func findWords(_ words: [String]) -> [String] { + let rowOne = "qwertyuiop", rowTwo = "asdfghjkl", rowThree = "zxcvbnm" - return words.filter { word in rowOne.contains(word) || rowTwo.contains(word) || rowThree.contains(word) } - } + return words.filter { word in rowOne.contains(word.lowercased()) || rowTwo.contains(word.lowercased()) || rowThree.contains(word.lowercased()) } + } +} - extension String { - func contains(_ word: String) -> Bool { - return word.filter { c in !self.contains(c) }.characters.count == 0 - } +extension String { + func contains(_ word: String) -> Bool { + return word.filter { c in !self.contains(c) }.count == 0 } -} \ No newline at end of file +}