当前位置:网站首页>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;
}
};
边栏推荐
- ISPRS2020/云检测:Transferring deep learning models for cloud detection between Landsat-8 and Proba-V
- RSE2020/云检测:基于弱监督深度学习的高分辨率遥感图像精确云检测
- What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
- 登录连接 CDB 和 PDB
- [PM2 details]
- VC编程入门浅谈「建议收藏」
- 爱因斯坦求和einsum
- 怎么选择外盘期货平台最正规安全?
- 模拟百囚徒问题
- Notes on common management commands of openshift
猜你喜欢

To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform

Privacy computing helps secure data circulation and sharing

记一次使用Windbg分析内存“泄漏”的案例

小林coding的内存管理章节

第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位

Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection

Star ring technology data security management platform defender heavy release

图片数据不够?我做了一个免费的图像增强软件

Leetcode daily question: the first unique character in the string

How awesome is the architecture of "12306"?
随机推荐
[paddleclas] common commands
使用QT遍历Json文档及搜索子对象
English sentence pattern reference
Generate classes from XML schema
[PM2 details]
开户注册股票炒股安全吗?有没有风险的?靠谱吗?
Penetrate the whole intranet through socks agent
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
LeetCode笔记:Weekly Contest 300
Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
Electron installation problems
ClickHouse(03)ClickHouse怎么安装和部署
Find the first k small element select_ k
mybash
nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)
Notes on common management commands of openshift
彻底理解为什么网络 I/O 会被阻塞?
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
About Estimation with Cross-Validation
