当前位置:网站首页>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;
}
};
边栏推荐
- 检查命名空间和类
- 记一次使用Windbg分析内存“泄漏”的案例
- Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
- Sibling components carry out value transfer (there is a sequence displayed)
- Privacy computing helps secure data circulation and sharing
- 从类生成XML架构
- buuctf-pwn write-ups (9)
- 含重复元素取不重复子集[如何取子集?如何去重?]
- Sophon autocv: help AI industrial production and realize visual intelligent perception
- 如何获取飞机穿过雷达两端的坐标
猜你喜欢

mybash

Record eval() and no in pytoch_ grad()

Simulate the hundred prisoner problem
![Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]](/img/b2/d019c3f0b85a6c0d334a092fa6c23c.png)
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]

第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”

《力扣刷题计划》复制带随机指针的链表

Tencent music launched its new product "quyimai", which provides music commercial copyright authorization

buuctf-pwn write-ups (9)
![Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]](/img/8b/a60fc36115580f018445e4c2a28a9d.png)
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]

ISPRS2020/云检测:Transferring deep learning models for cloud detection between Landsat-8 and Proba-V
随机推荐
How can cluster deployment solve the needs of massive video access and large concurrency?
Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
从类生成XML架构
Redis Foundation
Electron安装问题
OpenShift常用管理命令杂记
vulnhub之darkhole_2
Cmake tutorial step1 (basic starting point)
英语句式参考
集群部署如何解决海量视频接入与大并发需求?
JDBC reads a large amount of data, resulting in memory overflow
【pm2详解】
Clickhouse (03) how to install and deploy Clickhouse
兄弟组件进行传值(显示有先后顺序)
文章中的逻辑词
Introduction to VC programming on "suggestions collection"
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
Find the first k small element select_ k
Leetcode daily question: the first unique character in the string
mybash
