当前位置:网站首页>Sword finger offer 29 Print matrix clockwise
Sword finger offer 29 Print matrix clockwise
2022-07-02 02:00:00 【Yake1965】
The finger of the sword Offer 29. Print matrix clockwise
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;
}
}
边栏推荐
- MySQL constraints and multi table query example analysis
- Ks006 student achievement management system based on SSM
- 2022 Q2 - 提升技能的技巧总结
- With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry
- leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
- Parted command
- [Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
- Redis有序集合如何使用
- 开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
- 1218 square or round
猜你喜欢
如何远程、在线调试app?
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
Redis环境搭建和使用的方法
321. Chessboard segmentation (2D interval DP)
医药管理系统(大一下C语言课设)
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
OpenCASCADE7.6编译
AR增强现实可应用的场景
Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
随机推荐
How to build and use redis environment
1218 square or round
牛客网——华为题库(51~60)
matlab 使用 audioread 、 sound 读取和播放 wav 文件
电子协会 C语言 1级 32、计算2的幂
How to use a product to promote "brand thrill"?
MySQL constraints and multi table query example analysis
[技术发展-21]:网络与通信技术的应用与发展快速概览-1- 互联网网络技术
Matlab uses resample to complete resampling
MPLS experiment operation
1217 supermarket coin processor
Discussion on the idea of platform construction
MySQL如何解决delete大量数据后空间不释放的问题
C language 3-7 daffodils (enhanced version)
并发编程的三大核心问题
Construction and maintenance of business websites [12]
如何远程、在线调试app?
MySQL view concept, create view, view, modify view, delete view
Redis环境搭建和使用的方法
Post infiltration flow encryption