Swift


  • 0
    Q

    class Solution {
    func findWords(_ words: [String]) -> [String] {
    var returnStr = String
    for word in words {
    var isSuccess = true
    var index = 0
    for c in word.characters.map({ String($0) }) {
    if "qwertyuiop".contains(c) {
    if index == 1 || index == 0 {

                }else{
                    isSuccess = false
                }
                index = 1
            }else if "asdfghjkl".contains(c){
                if index == 2 || index == 0 {
                }else{
                    isSuccess = false
                }
                index = 2
            }else if "zxcvbnm".contains(c) {
                if index == 3 || index == 0 {
                }else{
                    isSuccess = false
                }
                index = 3
            }
        }
        if isSuccess == true {
            returnStr.append(word  )
        }
    }
    return returnStr
    }
    

    }


Log in to reply
 

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