Skip to content

79. Word Search #3

@kevin373738

Description

@kevin373738
 func exist(_ board: [[Character]], _ word: String) -> Bool {
         var hashMap: [Character: Int] = [:]
        var hasMapMatrix: [Character: Int] = [:]
        for value in Array(word) {
            hashMap[value, default: 0] += 1
        }
        
        for col in 0..<board.count {
            for row in 0..<board[col].count {
                hasMapMatrix[board[col][row], default: 0] += 1

            }
        }
        var isExist: Bool = false
        for char in word {
            if let countworld = hashMap[char], let countMatrix = hasMapMatrix[char], countworld <= countMatrix {
                isExist = true
            }
        }
      
        
        return isExist
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions