当前位置:网站首页>剑指 Offer 29. 顺时针打印矩阵
剑指 Offer 29. 顺时针打印矩阵
2022-07-02 01:54:00 【Yake1965】
剑指 Offer 29. 顺时针打印矩阵
class Solution {
public int[] spiralOrder(int[][] matrix) {
int m = matrix.length;
if (m == 0) return new int[]{
};
int n = matrix[0].length;
int[] res = new int[m * n];
int up = 0, down = m - 1;
int left = 0, right = n - 1;
int idx = 0;
while (left <= right && up <= down) {
for (int i = left; i <= right; i++) {
res[idx++] = matrix[up][i];
}
up++;
for (int i = up; i <= down; i++) {
res[idx++] = matrix[i][right];
}
right--;
if (left > right || up > down) break;
for (int i = right; i >= left; i--) {
res[idx++] = matrix[down][i];
}
down--;
for (int i = down; i >= up; i--) {
res[idx++] = matrix[i][left];
}
left++;
}
return res;
}
}
边栏推荐
- Using tabbar in wechat applet
- 479. Additive binary tree (interval DP on the tree)
- Construction and maintenance of business websites [10]
- 开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
- Six lessons to be learned for the successful implementation of edge coding
- Implementation principle of city selector component
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
- How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
- Construction and maintenance of business websites [11]
- Design and implementation of radio energy transmission system
猜你喜欢

Selection of field types for creating tables in MySQL database

Design and implementation of key value storage engine based on LSM tree

MATLAB realizes voice signal resampling and normalization, and plays the comparison effect

Self drawing of menu items and CListBox items

MySQL中一条SQL是怎么执行的

golang---锁

Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months

如何用一款产品推动「品牌的惊险一跃」?
![[技术发展-21]:网络与通信技术的应用与发展快速概览-1- 互联网网络技术](/img/2d/299fa5c76416f74bd1a693c433dd09.png)
[技术发展-21]:网络与通信技术的应用与发展快速概览-1- 互联网网络技术

分卷压缩,解压
随机推荐
5g/4g pole gateway_ Smart pole gateway
Five skills of adding audio codec to embedded system
电子协会 C语言 1级 33 、奇偶数判断
ES6 new method of string
Laravel artisan common commands
Experimental reproduction of variable image compression with a scale hyperprior
MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
1218 square or round
Develop those things: how to use go singleton mode to ensure the security of high concurrency of streaming media?
Android high frequency network interview topic must know and be able to compare Android development environment
Electronic Society C language level 1 32, calculate the power of 2
I Brief introduction of radio energy transmission technology
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Deep learning: a solution to over fitting in deep neural networks
Based on configured schedule, the given trigger will never fire
MPLS experiment operation
Volume compression, decompression
现货黄金分析的技巧有什么呢?
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
The difference between new and malloc