当前位置:网站首页>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;
}
}
边栏推荐
- 网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?
- You don't know how to deduce the location where HashSet stores elements?
- Array pointers and pointer arrays
- mmcv常用API介绍
- [chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point
- Bessel curve with n control points
- [typescript] defines the return value type of promise
- hashlips_ art_ Engine-1.0.6 usage
- SSL证书续费相关问题详解
- Operation of JSON file
猜你喜欢

How to create a CSR (certificate signing request) file?

9. naive Bayes

AI大模型落地大考,浪潮交出了怎样的答卷?
![[note] usage model tree of the unity resource tree structure virtualizingtreeview](/img/3e/fe5610c797a14554ad735172c3ab54.jpg)
[note] usage model tree of the unity resource tree structure virtualizingtreeview

Summary of common loss functions in pytorch

剑指 Offer 22. 链表中倒数第k个节点
![[notes] unity webgl input Chinese](/img/f7/805f510ff691227b4c2b529cc1099a.jpg)
[notes] unity webgl input Chinese

We strongly recommend more than a dozen necessary plug-ins for idea development

The minecraft server address cannot be refreshed.

Unity screenshot method
随机推荐
Pyinstaller flash back
How to use js to control the scroll bar of moving div
[untitled] user defined function
Unity screenshot method
Xctf--Web--Challenge--area Wp
Another download address for typro
Database SQL language 04 subquery and grouping function
Use the code cloud publicholiday project to determine whether a day is a working day
Xiaosha's lunch
Unity animator does not clip animation to play animation in segments
Expansion method of unity scanning circle
【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
Unity Catmull ROM curve
Unityshader learning notes - Basic Attributes
Unity 3D model operation and UI conflict Scrollview
Bev instance prediction based on monocular camera (iccv 2021)
Unity3d- use animator and code to control task walking
企事业单位源代码防泄露工作该如何进行
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
Unity gets the resolution of the game view