当前位置:网站首页>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;
}
};
边栏推荐
- 【机器人库】 awesome-robotics-libraries
- Computer graduation design PHP college classroom application management system
- Regular expressions: examples (1)
- LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
- Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
- Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
- [robot library] awesome robots Libraries
- RDD conversion operator of spark
- Publish your own toolkit notes using NPM
- 怎么检查GBase 8c数据库中的锁信息?
猜你喜欢
Computer graduation design PHP enterprise staff training management system
Using SA token to solve websocket handshake authentication
Selenium waiting mode
RDD partition rules of spark
剑指 Offer 30. 包含min函数的栈
MySQL lethal serial question 1 -- are you familiar with MySQL transactions?
Redis如何实现多可用区?
【机器人库】 awesome-robotics-libraries
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Structural theme model (I) STM package workflow
随机推荐
Concept of storage engine
vs code保存时 出现两次格式化
2022 edition illustrated network pdf
怎么检查GBase 8c数据库中的锁信息?
[coppeliasim] efficient conveyor belt
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
【无标题】数据库中一条查询SQL执行的过程
Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
在线怎么生成富文本
Online reservation system of sports venues based on PHP
【coppeliasim】高效传送带
Extracting key information from TrueType font files
SPI communication protocol
FTP server, ssh server (super brief)
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Numpy array index slice
General process of machine learning training and parameter optimization (discussion)
【机器人手眼标定】eye in hand