#79

Word Search

specialist · 915 · lc medium +31 · verified · 46.9% accepted · 17,567 likes · top 31%

play →

Description

Return true if string word can be formed by a path of sequentially adjacent (horizontally or vertically neighboring) cells in the m x n character grid board, where no cell may be reused.

Example 1:

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
Output: true

Example 2:

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
Output: true

Example 3:

Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
Output: false

Code

1
2
3