#212

Word Search II

master · 1750 · lc hard +32 · verified · 38.2% accepted · 10,135 likes · top 17%

play →

Description

Given an m x n grid board and a list of strings words, find all words from the list that can be traced on the board.

Each word traces through horizontally or vertically adjacent cells without reusing any cell within the same word.

Example 1:

Input: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
Output: ["eat","oath"]

Example 2:

Input: board = [["a","b"],["c","d"]], words = ["abcb"]
Output: []

Code

1
2
3