当前位置:网站首页>剑指 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;
}
}
边栏推荐
- Construction and maintenance of business websites [12]
- SQLite 3 of embedded database
- Number of palindromes in C language (leetcode)
- Architecture evolution from MVC to DDD
- 三分钟学会基础k线图知识
- 并发编程的三大核心问题
- Software No.1
- The concept, function, characteristics, creation and deletion of MySQL constraints
- Convolutional neural network (including code and corresponding diagram)
- 现货黄金分析的技巧有什么呢?
猜你喜欢

leetcode2310. 个位数字为 K 的整数之和(中等,周赛)

479. Additive binary tree (interval DP on the tree)

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

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

mysql列转行函数指的是什么
![[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

Memorabilia of domestic database in June 2022

Which is a good Bluetooth headset of about 300? 2022 high cost performance Bluetooth headset inventory

Have you stepped on the nine common pits in the e-commerce system?

【LeetCode 43】236. The nearest common ancestor of binary tree
随机推荐
遊戲思考15:全區全服和分區分服的思考
城市选择器组件实现原理
matlab 使用 audioread 、 sound 读取和播放 wav 文件
医药管理系统(大一下C语言课设)
Automatically browse pinduoduo products
MySQL主从延迟问题怎么解决
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Number of palindromes in C language (leetcode)
现货黄金分析的技巧有什么呢?
Openssl3.0 learning XXI provider encoder
Failed to transform file 'xxx' to match attributes
迁移云计算工作负载的四个基本策略
np.where 和 torch.where 用法
Redis有序集合如何使用
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
* and & symbols in C language
2022 Q2 - résumé des compétences pour améliorer les compétences
golang---锁
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable