当前位置:网站首页>剑指 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;
}
}
边栏推荐
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
- Learn basic K-line diagram knowledge in three minutes
- There are spaces in the for loop variable in the shell -- IFS variable
- Medical management system (C language course for freshmen)
- Implementation of Weibo system based on SSM
- leetcode373. 查找和最小的 K 对数字(中等)
- Electronic Association C language level 1 33, odd even number judgment
- 2022 Q2 - résumé des compétences pour améliorer les compétences
- 开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
- KS006基于SSM实现学生成绩管理系统
猜你喜欢

What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation

leetcode2312. 卖木头块(困难,周赛)

Six lessons to be learned for the successful implementation of edge coding

分卷压缩,解压

医药管理系统(大一下C语言课设)

Matlab uses resample to complete resampling

Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)

Develop those things: how to use go singleton mode to ensure the security of high concurrency of streaming media?

Redis环境搭建和使用的方法

1069. Division of convex polygons (thinking, interval DP)
随机推荐
leetcode2312. 卖木头块(困难,周赛)
5g/4g pole gateway_ Smart pole gateway
PR second training
This is the form of the K-line diagram (pithy formula)
What are the skills of spot gold analysis?
自动浏览拼多多商品
* and & symbols in C language
遷移雲計算工作負載的四個基本策略
遊戲思考15:全區全服和分區分服的思考
Using mongodb in laravel
What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
Game thinking 15: thinking about the whole region and sub region Services
1222. Password dropping (interval DP, bracket matching)
Android: the kotlin language uses grendao3, a cross platform app development framework
The technology boss is ready, and the topic of position C is up to you
Modeling essays series 124 a simple coding method
np. Where and torch Where usage
matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
D discard the virtual recovery method
The role of artificial intelligence in network security