3078. Match Alphanumerical Pattern in Matrix I
You are given a 2D integer matrix
board
and a 2D character matrixpattern
. Where0 <= board[r][c] <= 9
and each element ofpattern
is either a digit or a lowercase English letter.Your task is to find a submatrix of
board
that matchespattern
.An integer matrix
part
matchespattern
if we can replace cells containing letters inpattern
with some digits (each distinct letter with a unique digit) in such a way that the resulting matrix becomes identical to the integer matrixpart
. In other words,
The matrices have identical dimensions.
If
pattern[r][c]
is a digit, thenpart[r][c]
must be the same digit.If
1 pattern[r][c]is a letter
1 x:
- For every
pattern[i][j] == x
,part[i][j]
must be the same aspart[r][c]
.- For every
pattern[i][j] != x
,part[i][j]
must be different thanpart[r][c]
.Return an array of length
2
containing the row number and column number of the upper-left corner of a submatrix ofboard
which matchespattern
. If there is more than one such submatrix, return the coordinates of the submatrix with the lowest row index, and in case there is still a tie, return the coordinates of the submatrix with the lowest column index. If there are no suitable answers, return[-1, -1]
.
1 | class Solution { |