当前位置:网站首页>2022.07.03(LC_6111_统计放置房子的方式数)
2022.07.03(LC_6111_统计放置房子的方式数)
2022-07-05 00:08:00 【Leeli9316】
方法:模拟
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public int[][] spiralMatrix(int m, int n, ListNode head) {
int[][] res = new int[m][n];
int up = 0, down = m - 1, left = 0, right = n - 1;
while (true) {
//从左到右
for (int col = left; col <= right; col++) {
if (head != null) {
res[up][col] = head.val;
head = head.next;
} else {
res[up][col] = -1;
}
}
if (++up > down) break;
//从上到下
for (int row = up; row <= down; row++) {
if (head != null) {
res[row][right] = head.val;
head = head.next;
} else {
res[row][right] = -1;
}
}
if (--right < left) break;
//从右到左
for (int col = right; col >= left; col--) {
if (head != null) {
res[down][col] = head.val;
head = head.next;
} else {
res[down][col] = -1;
}
}
if (--down < up) break;
//从下到上
for (int row = down; row >= up; row--) {
if (head != null) {
res[row][left] = head.val;
head = head.next;
} else {
res[row][left] = -1;
}
}
if (++left > right) break;
}
return res;
}
}
边栏推荐
- Illustrated network: what is gateway load balancing protocol GLBP?
- 基本放大电路的学习
- [IELTS reading] Wang Xiwei reading P4 (matching1)
- 积分商城游戏设置的基本要点
- How to do the project of computer remote company in foreign Internet?
- 人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
- 使用快解析搭建自己的minecraft服务器
- [IELTS reading] Wang Xiwei reading P3 (heading)
- Is it safe to open an account in the College of Finance and economics? How to open an account?
- Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
猜你喜欢
"Xiaodeng" domain password policy enhancer in operation and maintenance
Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
图解网络:什么是网关负载均衡协议GLBP?
Application of multi loop instrument in base station "switching to direct"
多回路仪表在基站“转改直”方面的应用
Skills in analyzing the trend chart of London Silver
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
Combien de temps faut - il pour obtenir un certificat PMP?
Netcore3.1 JSON web token Middleware
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
随机推荐
Illustrated network: what is gateway load balancing protocol GLBP?
快解析内网穿透帮助企业快速实现协同办公
"Xiaodeng" domain password policy enhancer in operation and maintenance
雅思考试流程、需要具体注意些什么、怎么复习?
Is it safe to open and register new bonds? Is there any risk? Is it reliable?
Parsing of XML
45 year old professor, she threw two super unicorns
初识ROS
[ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
Enterprise application business scenarios, function addition and modification of C source code
abc 258 G - Triangle(bitset)
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
A new method for analyzing the trend chart of London Silver
P4408 [NOI2003] 逃学的小孩(树的直径)
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
js如何实现数组转树
Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
Application of fire fighting system based on 3D GIS platform
Consolidated expression C case simple variable operation
Fast analysis -- easy to use intranet security software