当前位置:网站首页>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;
}
}边栏推荐
- Meet ThreadPoolExecutor
- uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
- Consolidated expression C case simple variable operation
- 如何有效对直流列头柜进行监测
- uniapp上传头像
- Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
- The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
- PermissionError: [Errno 13] Permission denied: ‘data. csv‘
- Expand your kubecl function
- Using the uniapp rich text editor
猜你喜欢
随机推荐
[ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
实战模拟│JWT 登录认证
[JS] - [dynamic planning] - Notes
业务实现-日志写到同一个行数据里面
Application of fire fighting system based on 3D GIS platform
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
Chinese verification of JS regular expressions (turn)
Cross domain request
45岁教授,她投出2个超级独角兽
Face recognition 5- insight face padding code practice notes
How to apply for PMP project management certification examination?
ORB(Oriented FAST and Rotated BRIEF)
取得PMP證書需要多長時間?
How to reduce the stock account Commission and stock speculation commission? Is it safe to open an online account
使用快解析搭建自己的minecraft服务器
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
abc 258 G - Triangle(bitset)
Fast analysis -- easy to use intranet security software
Advanced template





![[IELTS reading] Wang Xiwei reading P4 (matching1)](/img/91/1b3f85410035f65acb0c205185f698.png)



