当前位置:网站首页>Sword finger offer 29 Print matrix clockwise
Sword finger offer 29 Print matrix clockwise
2022-07-06 02:20:00 【anieoo】
Original link ; The finger of the sword Offer 29. Print matrix clockwise
solution:
Same solution as spiral matrix
class Solution {
public:
int dx[4] = {0, 1, 0, -1},dy[4] = {1, 0, -1, 0};
vector<int> spiralOrder(vector<vector<int>>& matrix) {
vector<int> res; // Define the return value
if(matrix.size() == 0) return res;
int m = matrix.size(),n = matrix[0].size();
vector<vector<bool>> sta(m, vector<bool> (n, false));
for(int i = 0,x = 0,y = 0,d = 0;i < m * n;i++) {
res.push_back(matrix[x][y]);
sta[x][y] = true;
int a = x + dx[d],b = y + dy[d];
if(a < 0 || a == m || b < 0 || b == n || sta[a][b]){
d = (d + 1) % 4;
a = x + dx[d],b = y + dy[d];
}
x = a,y = b;
}
return res;
}
};边栏推荐
- [Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
- genius-storage使用文档,一个浏览器缓存工具
- 机器学习训练与参数优化的一般过程 (讨论)
- Gbase 8C database upgrade error
- [robot library] awesome robots Libraries
- 【coppeliasim】高效传送带
- Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
- Redis daemon cannot stop the solution
- Initial understanding of pointer variables
- 2022 edition illustrated network pdf
猜你喜欢

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Use the list component to realize the drop-down list and address list

安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3

2022 edition illustrated network pdf
![[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!](/img/aa/af98b588efd61d71b1b02609817c49.png)
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!

Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械

Ue4- how to make a simple TPS role (II) - realize the basic movement of the role

在线怎么生成富文本

Numpy array index slice

MySQL lethal serial question 1 -- are you familiar with MySQL transactions?
随机推荐
Use the list component to realize the drop-down list and address list
Initial understanding of pointer variables
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
ftp上传文件时出现 550 Permission denied,不是用户权限问题
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
Overview of spark RDD
剑指 Offer 30. 包含min函数的栈
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
Install redis
Easy to use js script
Xshell 7 Student Edition
论文笔记: 图神经网络 GAT
Computer graduation design PHP campus restaurant online ordering system
一位博士在华为的22年
Redis如何实现多可用区?
Social networking website for college students based on computer graduation design PHP
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
Selenium waiting mode
Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
SSM assembly