当前位置:网站首页>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;
}
}边栏推荐
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- Financial markets, asset management and investment funds
- 他做国外LEAD,用了一年时间,把所有房贷都还清了
- 22-07-02周总结
- Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
- [IELTS reading] Wang Xiwei reading P3 (heading)
- Microservice
- AcWing164. 可达性统计(拓扑排序+bitset)
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- Cross domain request
猜你喜欢
![P3304 [SDOI2013]直径(树的直径)](/img/5c/984675bf4517481f80f54657c6c7ad.png)
P3304 [SDOI2013]直径(树的直径)

Continuous modification of business scenario functions

同事的接口文档我每次看着就头大,毛病多多。。。

How long does it take to obtain a PMP certificate?

OpenHarmony资源管理详解

Combien de temps faut - il pour obtenir un certificat PMP?

【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)

Tester's algorithm interview question - find mode

机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)

In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi
随机推荐
初识ROS
Business implementation - the log is written to the same row of data
多回路仪表在基站“转改直”方面的应用
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
The pit of sizeof operator in C language
Summary of week 22-07-02
Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities
[ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
用快解析内网穿透实现零成本自建网站
「运维有小邓」域密码策略强化器
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
如何报考PMP项目管理认证考试?
使用快解析搭建自己的minecraft服务器
S32 design studio for arm 2.2 quick start
How long does it take to obtain a PMP certificate?
In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
如何将自己的代码作品快速存证,已更好的保护自己劳动成果
跨域请求
Instructions for go defer