Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the path problem in Matrix with the skill of golang brushing leetcode

Shulou Source: shulou.com Published: 2022-06-01 12:48:32 10月30日 Update

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

Tags: Paths matrices characters strings squares articles one grid tips questions again letters more examples input output good practical one line code content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn MariaDB Redmi Linux