当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
How awesome is the architecture of "12306"?
Memory management chapter of Kobayashi coding
星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
如何获取飞机穿过雷达两端的坐标
Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
修复漏洞 - mysql 、es
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
吳恩達團隊2022機器學習課程,來啦
Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
随机推荐
Copy the linked list with random pointer in the "Li Kou brush question plan"
Career advancement Guide: recommended books for people in big factories
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
南京大学:新时代数字化人才培养方案探讨
Use of print function in MATLAB
【在优麒麟上使用Electron开发桌面应】
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
Einstein sum einsum
文章中的逻辑词
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
星环科技数据安全管理平台 Defensor重磅发布
兄弟组件进行传值(显示有先后顺序)
写作写作写作写作
[utiliser Electron pour développer le Bureau sur youkirin devrait]
Fix vulnerability - mysql, ES
ClickHouse(03)ClickHouse怎么安装和部署