How to solve the path problem in Matrix with the skill of golang brushing leetcode
This article will explain in detail how to solve the path problem in the matrix with golang leetcode skills. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Design a function to determine whether there is a path in a matrix that contains all the characters of a string. The path can start with any grid in the matrix, and each step can move one grid to the left, right, up, and down in the matrix. If a path passes through a lattice of a matrix, the path cannot enter the grid again. For example, the following 3 × 4 matrix contains the path of the string "bfce" (the letters in the path are marked in bold).
[["a", "b", "c", "e"]
["s", "f", "c", "s"]
["a", "d", "e", "e"]
However, the path to the string "abfb" is not included in the matrix, because after the first character b of the string occupies the first row and the second grid in the matrix, the path cannot enter the grid again.
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", "d"]], word = "abcd"
Output: false
Tip:
one