10 vector<vector<int>> matrix(n, vector<int>(n));
12 int left = 0, right = n - 1, top = 0, bottom = n - 1;
14 while (left <= right && top <= bottom)
16 for (
int j = left; j <= right; ++j)
17 matrix[top][j] = num++;
20 for (
int i = top; i <= bottom; ++i)
21 matrix[i][right] = num++;
26 for (
int j = right; j >= left; --j)
27 matrix[bottom][j] = num++;
33 for (
int i = bottom; i >= top; --i)
34 matrix[i][left] = num++;