Day i do not know

This commit is contained in:
Electrominch
2022-10-18 00:45:31 +03:00
parent 01c5720116
commit 284b6ff10c
72 changed files with 1256 additions and 12 deletions

View File

@@ -0,0 +1,35 @@
namespace _542._01_Matrix;
public class Solution
{
public int[][] UpdateMatrix(int[][] mat)
{
bool hasChanges = true;
while(hasChanges)
{
hasChanges = false;
for (int y = 0; y < mat.Length; y++)
{
for (int x = 0; x < mat[y].Length; x++)
{
if (mat[y][x] == 0)
continue;
int min = int.MaxValue;
for (int i = 1; i < 9; i += 2)
{
int newY = i / 3 + y - 1;
int newX = i % 3 + x - 1;
if (newY >= 0 && newY < mat.Length && newX >= 0 && newX < mat[newY].Length)
{
min = Math.Min(min, mat[newY][newX]);
}
}
if(mat[y][x] != min + 1)
hasChanges = true;
mat[y][x] = min + 1;
}
}
}
return mat;
}
}