Clean and Simple SWIFT Solution!!!

  • 0
    class Solution {
        func findWords(_ words: [String]) -> [String] {
            let topLine: Set<Character> =  ["q","w","e","r","t","y","u","i","o","p"]
            let secondLine: Set<Character> = ["a","s","d","f","g","h","j","k","l"]
            let bottomLine: Set<Character> = ["z","x","c","v","b","n","m"]
            var foundWords = [String]()
            words.forEach { word in
                let set = Set(word.lowercased().characters)
                if set.isSubset(of: topLine) || set.isSubset(of: secondLine) || set.isSubset(of: bottomLine) {
            return foundWords

    My solution runtime is at 53% for Swift solutions. How would you make it faster?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.