当前位置:网站首页>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;
}
}
边栏推荐
- [论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
- Enterprise application business scenarios, function addition and modification of C source code
- 用快解析内网穿透实现零成本自建网站
- 人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
- Paddleocr tutorial
- PaddleOCR教程
- [paper reading] cavemix: a simple data augmentation method for brain vision segmentation
- Fast analysis -- easy to use intranet security software
- 如果炒股开华泰证券的户,在网上开户安全吗?
- Continuous modification of business scenario functions
猜你喜欢
Date time type and format in MySQL
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
Application of fire fighting system based on 3D GIS platform
业务场景功能的继续修改
IELTS examination process, what to pay attention to and how to review?
使用快解析搭建自己的minecraft服务器
He worked as a foreign lead and paid off all the housing loans in a year
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
如何用快解析自制IoT云平台
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
随机推荐
打新债开户注册安全吗?有没有风险的?靠谱吗?
22-07-02周总结
初识ROS
Consolidated expression C case simple variable operation
Tester's algorithm interview question - find mode
How to reduce the stock account Commission and stock speculation commission? Is it safe to open an online account
How to save your code works quickly to better protect your labor achievements
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
Instructions for go defer
Parsing of XML
「运维有小邓」域密码策略强化器
Is the account opening link of Huatai Securities with low commission safe?
实战模拟│JWT 登录认证
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
跨域请求
Actual combat simulation │ JWT login authentication
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
Is it safe to open an account in the College of Finance and economics? How to open an account?
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent