当前位置:网站首页>Sword finger offer 29 Print matrix clockwise
Sword finger offer 29 Print matrix clockwise
2022-06-30 05:37:00 【South wind knows easy***】
class Solution {
public int[] spiralOrder(int[][] matrix) {
if(matrix.length==0) return new int[]{
};
int m=matrix.length;
int n=matrix[0].length;
int[] res=new int[(m)*(n)];
int top=0;int bottom=matrix.length-1; int left=0;int right=matrix[0].length-1;
int x=0;
while(true){
for(int i=left;i<=right;i++) res[x++]=matrix[top][i];
if(++top>bottom) break;
for(int i=top;i<=bottom;i++) res[x++]=matrix[i][right];
if(--right<left) break;
for(int i=right;i>=left;i--) res[x++]=matrix[bottom][i];
if(--bottom<top) break;
for(int i=bottom;i>=top;i--) res[x++]=matrix[i][left];
if(++left>right) break;
}
return res;
}
}
边栏推荐
- Another download address for typro
- Idea of capturing mobile terminal variant combination
- Use the code cloud publicholiday project to determine whether a day is a working day
- VFPBS上传EXCEL并保存MSSQL到数据库中
- /Path/to/ idiom, not a command
- Sound network, standing in the "soil" of the Internet of things
- Installation and getting started with pytoch
- Is it safe to open an account and trade with a compass?
- 2022年,谁在推动音视频产业的新拐点?
- Intellj idea generates jar packages for projects containing external lib to other projects. The method refers to the jar package written by itself
猜你喜欢

【LeetCode】Easy | 232. Using stack to realize queue (pure C manual tearing stack)

网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?

Redistemplate common method summary

Basic operations of C language

Rotating box target detection mmrotate v0.3.1 getting started

终端便捷ssh(免密)连接

Sound net, debout dans le "sol" de l'IOT

【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点

剑指 Offer 18. 删除链表的节点

强烈推荐十几款IDEA开发必备的插件
随机推荐
Learning about functions QAQ
Another download address for typro
Unityshader learning notes - Basic Attributes
[notes] unity webgl input Chinese
C. Divan and bitwise operations
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
声网,站在物联网的“土壤”里
Transfer the token on the matic-erc20 network to the matic polygon
Unity determines whether the UI is clicked
Is it safe to open an account and trade with a compass?
Unity mobile end sliding screen rotation
Stack overflow caused by C # using protobuf stack overflow
PyGame. Why can't I exit when I click X in the window? I can only exit when I return idle
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
AI大模型落地大考,浪潮交出了怎样的答卷?
Unity call Exe program
C语言基础小操作
Bessel curve with n control points
English语法_形容词/副词3级-最高级
14x1.5cm vertical label is a little difficult, VFP calls bartender to print