当前位置:网站首页>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;
}
}边栏推荐
- 积分商城游戏设置的基本要点
- PMP证书续证流程
- Consolidated expression C case simple variable operation
- Basic points of the game setup of the points mall
- Is the account opening link of Huatai Securities with low commission safe?
- Summary of week 22-07-02
- [paper reading] Tun det: a novel network for meridian ultra sound nodule detection
- [paper reading] cavemix: a simple data augmentation method for brain vision segmentation
- 【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
- 海思3559万能平台搭建:YUV422的踩坑记录
猜你喜欢
![[paper reading] cavemix: a simple data augmentation method for brain vision segmentation](/img/41/eb790e7419a158e985fa503bd7dc17.png)
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation

Design of emergency lighting evacuation indication system for urban rail transit station

45 year old professor, she threw two super unicorns

Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
![[paper reading] Tun det: a novel network for meridian ultra sound nodule detection](/img/25/e2366cabf00e55664d16455a6049e0.png)
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection

Consolidated expression C case simple variable operation

How long does it take to obtain a PMP certificate?

初识ROS

IT转测试岗,从迷茫到坚定我究竟付出了什么?

机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
随机推荐
Illustrated network: what is gateway load balancing protocol GLBP?
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
Paddleocr tutorial
快解析——好用的内网安全软件
XML的解析
Five papers recommended for the new development of convolutional neural network in deep learning
45岁教授,她投出2个超级独角兽
打新债开户注册安全吗?有没有风险的?靠谱吗?
OSEK standard ISO_ 17356 summary introduction
IELTS examination process, what to pay attention to and how to review?
Cross domain request
跨域请求
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
如何将自己的代码作品快速存证,已更好的保护自己劳动成果
[Peking University] tensorflow2.0-1-opening
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
城市轨道交通站应急照明疏散指示系统设计
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
Chinese verification of JS regular expressions (turn)