标签:nbsp color off col 数字 solution matrix tom subject
class Solution { public: vector<int> printMatrix(vector<vector<int>> matrix) { int bottom = matrix.size() - 1; int right = matrix[0].size() - 1; vector<int> res; if (bottom < 0 || right < 0) return res; int top = 0, left = 0; while (left <= right && top <= bottom) { // 左到右 for (int i = left; i <= right; i++) res.push_back(matrix[top][i]); // 上到下 for (int j = top + 1; j <= bottom; j++) res.push_back(matrix[j][right]); // 右到左 if (top != bottom) for (int k = right - 1; k >= left; k--) res.push_back(matrix[bottom][k]); // 下到上 if (left != right) for (int l = bottom - 1; l > top; l--) res.push_back(matrix[l][left]); left++, top++, right--, bottom--; } return res; } };
标签:nbsp color off col 数字 solution matrix tom subject
原文地址:https://www.cnblogs.com/ruoh3kou/p/10053947.html