当前位置:网站首页>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;
}
};
边栏推荐
- Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- Writing writing writing
- Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
- 最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
- nano的CAN通信
- Clickhouse (03) how to install and deploy Clickhouse
- Use JMeter to record scripts and debug
- 南京大学:新时代数字化人才培养方案探讨
- node_exporter内存使用率不显示
猜你喜欢
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
Unicode processing in response of flash interface
ISPRS2020/云检测:Transferring deep learning models for cloud detection between Landsat-8 and Proba-V
buuctf-pwn write-ups (9)
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
Memory management chapter of Kobayashi coding
Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.
Wu Enda team 2022 machine learning course, coming
模拟百囚徒问题
彻底理解为什么网络 I/O 会被阻塞?
随机推荐
《力扣刷题计划》复制带随机指针的链表
ConvMAE(2022-05)
ConvMAE(2022-05)
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
Leetcode notes: Weekly contest 300
[paddleclas] common commands
【在优麒麟上使用Electron开发桌面应】
"Xiaodeng in operation and maintenance" is a single sign on solution for cloud applications
GFS distributed file system
Sophon autocv: help AI industrial production and realize visual intelligent perception
苹果手机炒股安全吗?打新债是骗局吗?
Find the first k small element select_ k
Nanjing University: Discussion on the training program of digital talents in the new era
破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
Simulate the hundred prisoner problem
VC编程入门浅谈「建议收藏」
寻找第k小元素 前k小元素 select_k
About Statistical Power(统计功效)
New words new words new words new words [2]
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?