当前位置:网站首页>LeetCode 6111. Spiral matrix IV
LeetCode 6111. Spiral matrix IV
2022-07-05 18:19:00 【HumbleFool】
LeetCode 6111. Spiral matrix IV
Writing spiral matrix with offset method
/** * 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;
}
};
边栏推荐
- About Estimation with Cross-Validation
- [PM2 details]
- 文章中的逻辑词
- How to obtain the coordinates of the aircraft passing through both ends of the radar
- About Statistical Power(统计功效)
- Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
- GIMP 2.10教程「建议收藏」
- 使用Jmeter虚拟化table失败
- rust统计文件中单词出现的次数
- node_ Exporter memory usage is not displayed
猜你喜欢

Fix vulnerability - mysql, ES

The 2022 China Xinchuang Ecological Market Research and model selection evaluation report released that Huayun data was selected as the mainstream manufacturer of Xinchuang IT infrastructure!

Vulnhub's darkhole_ two

nano的CAN通信

Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry

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

《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
![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?]

Wu Enda team 2022 machine learning course, coming

Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
随机推荐
英语句式参考
The 10th global Cloud Computing Conference | Huayun data won the "special contribution award for the 10th anniversary of 2013-2022"
Record eval() and no in pytoch_ grad()
Logical words in Articles
第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
[paddlepaddle] paddedetection face recognition custom data set
含重复元素取不重复子集[如何取子集?如何去重?]
[use electron to develop desktop on youqilin]
寻找第k小元素 前k小元素 select_k
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
Check namespaces and classes
苹果手机炒股安全吗?打新债是骗局吗?
node_ Exporter memory usage is not displayed
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
集群部署如何解决海量视频接入与大并发需求?
vulnhub之darkhole_2
Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
Writing writing writing
访问数据库使用redis作为mysql的缓存(redis和mysql结合)