Re: [闲聊] 每日leetcode

楼主: oin1104 (是oin的说)   2024-08-08 11:29:58
※ 引述 《involution》 之铭言:
:  
: 885. Spiral Matrix III
:  
: 无聊的模拟题 只是想分享一下绕圈圈的四个方向有几种写法
:  
:  
: 2.
:  
: dx = [0, 1, 0, -1]
: dy = [1, 0, -1, 0]
:  
题目:
让你在一个矩阵里面从指定的地方开始绕圈圈
超过矩阵就继续走
然后问你经过哪里了
思路:
模拟
我让jiwp去当d x或y
因为我想要jiwp的 x或y染色体
你懂我意思吗
```cpp
class Solution {
public:
vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cSta
rt)
{
int n = 1 ;
int len = 1;
int all = rows*cols;
vector<vector<int>> paper;
int r = rStart;
int c = cStart;
vector<int> ji = {0,1,0,-1};
vector<int> wp = {1,0,-1,0};
paper.push_back({r,c});
while(n<all)
{
for(int k = 0 ; k < 4 ; k ++)
{
for(int i = 0 ; i < len ; i ++)
{
r+=ji[k];
c+=wp[k];
if(r>=0&&r<rows&&c>=0&&c<cols)
{
paper.push_back({r,c});
n++;
}
}
if(k &1)len++;
}
}
return paper;
}
};
```
作者: SydLrio (狂岚嘴砲)   2024-08-08 11:31:00
你有什么用
作者: JIWP (JIWP)   2024-08-08 11:42:00
你有什么用

Links booklink

Contact Us: admin [ a t ] ucptt.com