当前位置:网站首页>LeetCode 6111. 螺旋矩阵 IV
LeetCode 6111. 螺旋矩阵 IV
2022-07-05 18:12:00 【HumbleFool】
偏移量法写螺旋矩阵
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
vector<vector<int>> spiralMatrix(int n, int m, ListNode* head) {
vector<vector<int>> res(n, vector<int>(m, -1));
int x = 0, y = 0, d = 1;
for(int i = 0; i < n * m && head; i ++)
{
res[x][y] = head -> val;
int a = a + dx[d], b = b + dy[d];
if(a < 0 || a >= n || b < 0 || b >= m || res[a][b] != -1)
{
d = (d + 1) % 4;
a = x + dx[d], b = y + dy[d];
}
x = a, y = b;
head = head -> next;
}
return res;
}
};
边栏推荐
- Tupu software digital twin | visual management system based on BIM Technology
- 小林coding的内存管理章节
- 文章中的逻辑词
- 第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
- 检查命名空间和类
- Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
- Leetcode exercise - 206 Reverse linked list
- 生词生词生词生词[2]
- Generate classes from XML schema
- 怎么选择外盘期货平台最正规安全?
猜你喜欢

Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.

Sophon KG升级3.1:打破数据间壁垒,解放企业生产力

小林coding的内存管理章节
![[JMeter] advanced writing method of JMeter script: all variables, parameters (parameters can be configured by Jenkins), functions, etc. in the interface automation script realize the complete business](/img/a6/aa0b8d30913dc64f3c0cd891528c40.png)
[JMeter] advanced writing method of JMeter script: all variables, parameters (parameters can be configured by Jenkins), functions, etc. in the interface automation script realize the complete business

Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀

Binder开辟线程数过多导致主线程ANR异常

修复漏洞 - mysql 、es

Record eval() and no in pytoch_ grad()

图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统

ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
随机推荐
About Statistical Power(统计功效)
修复漏洞 - mysql 、es
Record eval() and no in pytoch_ grad()
Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
深拷贝与浅拷贝【面试题3】
Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
Gimp 2.10 tutorial "suggestions collection"
【pm2详解】
Crontab 日志:如何记录我的 Cron 脚本的输出
rsync
写作写作写作写作
[TestLink] testlink1.9.18 solutions to common problems
vulnhub之darkhole_2
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
Leetcode daily question: the first unique character in the string
Cmake tutorial step1 (basic starting point)
Find the first k small element select_ k
图片数据不够?我做了一个免费的图像增强软件
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
