-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01 Matrix.cpp
39 lines (33 loc) · 1.21 KB
/
01 Matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// class Solution {
// public:
// vector<int> di = {1, 0, -1, 0};
// vector<int> dj = {0, 1, 0, -1};
// vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {
// int m = mat.size();
// int n = mat[0].size();
// vector<vector<int>> distance(m, vector<int> (n, -1));
// queue<pair<int, int>> q;
// for (int i = 0; i < m; ++i) {
// for (int j = 0; j < n; ++j) {
// if (mat[i][j] == 0) {
// distance[i][j] = 0;
// q.push({i, j});
// }
// }
// }
// while (!q.empty()) {
// int i = q.front().first;
// int j = q.front().second;
// q.pop();
// for (int dir = 0; dir < 4; ++dir) {
// int ii = i + di[dir];
// int jj = j + dj[dir];
// if (ii >= 0 and ii < m and jj >= 0 and jj < n and distance[ii][jj] == -1) {
// distance[ii][jj] = distance[i][j] + 1;
// q.push({ii, jj});
// }
// }
// }
// return distance;
// }
// };