当前位置:网站首页>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;
}
}
边栏推荐
- 5g/4g pole gateway_ Smart pole gateway
- matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
- 如何远程、在线调试app?
- 479. Additive binary tree (interval DP on the tree)
- Feature extraction and detection 16 brisk feature detection and matching
- 开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
- The difference between new and malloc
- Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
- 医药管理系统(大一下C语言课设)
- 电子协会 C语言 1级 32、计算2的幂
猜你喜欢

并发编程的三大核心问题

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

matlab 使用 resample 完成重采样

Opengauss database backup and recovery guide

PR second training

How to execute an SQL in MySQL

分卷压缩,解压

Medical management system (C language course for freshmen)

leetcode2309. The best English letters with both upper and lower case (simple, weekly)
![[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing](/img/56/87bc8fca9ceeab6484f567f7231fdb.png)
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
随机推荐
leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)
Niuke - Huawei question bank (51~60)
What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality
Should enterprises choose server free computing?
【LeetCode 43】236. The nearest common ancestor of binary tree
【C#】使用正则校验内容
C language 3-7 daffodils (enhanced version)
Design and implementation of key value storage engine based on LSM tree
Matlab uses audioread and sound to read and play WAV files
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
5g/4g pole gateway_ Smart pole gateway
Architecture evolution from MVC to DDD
Medical management system (C language course for freshmen)
分卷压缩,解压
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
How to execute an SQL in MySQL
leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
Construction and maintenance of business websites [10]