当前位置:网站首页>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;
}
}
边栏推荐
- Cross domain? Homology? Understand what is cross domain at once
- Construction and maintenance of business websites [12]
- Construction and maintenance of business websites [13]
- 【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
- Word search applet design report based on cloud development +ppt+ project source code + demonstration video
- 2022 Q2 - résumé des compétences pour améliorer les compétences
- 2022 Q2 - 提升技能的技巧总结
- 人工智能在网络安全中的作用
- 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
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
猜你喜欢
Architecture evolution from MVC to DDD
Software No.1
Cross domain? Homology? Understand what is cross domain at once
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
The role of artificial intelligence in network security
Golang lock
MySQL主从延迟问题怎么解决
What are the skills of spot gold analysis?
leetcode2305. 公平分发饼干(中等,周赛,状压dp)
Learn basic K-line diagram knowledge in three minutes
随机推荐
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
MySQL如何解决delete大量数据后空间不释放的问题
TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
There are spaces in the for loop variable in the shell -- IFS variable
leetcode2309. The best English letters with both upper and lower case (simple, weekly)
Implementation of Weibo system based on SSM
The concept, function, characteristics, creation and deletion of MySQL constraints
How to build and use redis environment
Feature extraction and detection 16 brisk feature detection and matching
What are the skills of spot gold analysis?
Opengauss database backup and recovery guide
How to use redis ordered collection
C language 3-7 daffodils (enhanced version)
What is AQS and its principle
Six lessons to be learned for the successful implementation of edge coding
【深度学习】infomap 人脸聚类 facecluster
321. Chessboard segmentation (2D interval DP)
Matlab uses audioread and sound to read and play WAV files
This is the form of the K-line diagram (pithy formula)
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu