当前位置:网站首页>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;
}
};
边栏推荐
- Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
- 第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
- 吴恩达团队2022机器学习课程,来啦
- Clickhouse (03) how to install and deploy Clickhouse
- EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
- jdbc读大量数据导致内存溢出
- 最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
- Penetrate the whole intranet through socks agent
- The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
- 破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
猜你喜欢
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
buuctf-pwn write-ups (9)
vulnhub之darkhole_2
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
吳恩達團隊2022機器學習課程,來啦
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
Privacy computing helps secure data circulation and sharing
随机推荐
图像分类,看我就够啦!
模拟百囚徒问题
vulnhub之darkhole_2
[PM2 details]
Image classification, just look at me!
记录Pytorch中的eval()和no_grad()
消除`if()else{ }`写法
Notes on common management commands of openshift
生词生词生词生词[2]
[paddlepaddle] paddedetection face recognition custom data set
记一次使用Windbg分析内存“泄漏”的案例
matlab内建函数怎么不同颜色,matlab分段函数不同颜色绘图
Let more young people from Hong Kong and Macao know about Nansha's characteristic cultural and creative products! "Nansha kylin" officially appeared
ConvMAE(2022-05)
通过SOCKS代理渗透整个内网
星环科技数据安全管理平台 Defensor重磅发布
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
IDC report: Tencent cloud database ranks top 2 in the relational database market!
JDBC reads a large amount of data, resulting in memory overflow
热通孔的有效放置如何改善PCB设计中的热管理?