当前位置:网站首页>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;
}
};
边栏推荐
- 检查命名空间和类
- Writing writing writing
- 第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
- 隐私计算助力数据的安全流通与共享
- Record eval() and no in pytoch_ grad()
- Eliminate the writing of 'if () else{}'
- MATLAB中print函数使用
- Matlab built-in function how different colors, matlab subsection function different colors drawing
- [PM2 details]
- 热通孔的有效放置如何改善PCB设计中的热管理?
猜你喜欢

分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载

破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台

Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀

FCN: Fully Convolutional Networks for Semantic Segmentation

nano的CAN通信

瀚升优品app翰林优商系统开发功能介绍

@Extension、@SPI注解原理

vulnhub之darkhole_2

About Statistical Power(统计功效)

使用JMeter录制脚本并调试
随机推荐
[JMeter] advanced writing method of JMeter script: all variables, parameters (parameters can be configured by Jenkins), functions, etc. in the interface automation script realize the complete business
LeetCode笔记:Weekly Contest 300
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
记录Pytorch中的eval()和no_grad()
寻找第k小元素 前k小元素 select_k
吳恩達團隊2022機器學習課程,來啦
爱因斯坦求和einsum
Copy the linked list with random pointer in the "Li Kou brush question plan"
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
写作写作写作写作
LeetCode 6111. 螺旋矩阵 IV
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
Image classification, just look at me!
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]
buuctf-pwn write-ups (9)
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
【在优麒麟上使用Electron开发桌面应】
【在優麒麟上使用Electron開發桌面應】
Notes on common management commands of openshift