704.二分查找
https://leetcode.cn/problems/binary-search/description/
59.螺旋矩阵II
https://leetcode.cn/problems/spiral-matrix-ii/description/、
参考题解写出
54.螺旋矩阵
https://leetcode.cn/problems/spiral-matrix/description/
class Solution { public: vector<int> spiralOrder(vector<vector<int>>& matrix) { int m = matrix.size(); int n = matrix[0].size(); int t = 0, l = 0, b = m - 1, r = n - 1; vector<int> ans; int num_size = m*n; while(num_size > 0){ for(int i = l; i <= r && num_size > 0; i++){ ans.push_back(matrix[t][i]);//从左到右 num_size--; } t++; for(int i = t; i <= b && num_size > 0; i++){// 从上到下 ans.push_back(matrix[i][r]); num_size--; } r--; for(int i = r; i >= l && num_size > 0; i--){//从右到左 ans.push_back(matrix[b][i]); num_size--; } b--; for(int i = b; i >= t && num_size > 0; i--){//从下到上 ans.push_back(matrix[i][l]); num_size--; } l++; } return ans; } };
标签:matrix,int,随想录,--,num,版刷题,ans,突击,size From: https://www.cnblogs.com/spp20/p/18412131