当前位置:网站首页>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;
}
};
边栏推荐
- Social networking website for college students based on computer graduation design PHP
- 从顶会论文看2022年推荐系统序列建模的趋势
- 安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
- SQL statement
- Genius storage uses documents, a browser caching tool
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- 2022 PMP project management examination agile knowledge points (8)
- PHP campus financial management system for computer graduation design
- [coppeliasim] efficient conveyor belt
- Lecture 4 of Data Engineering Series: sample engineering of data centric AI
猜你喜欢
Initial understanding of pointer variables
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
数据工程系列精讲(第四讲): Data-centric AI 之样本工程
Virtual machine network, networking settings, interconnection with host computer, network configuration
Concept of storage engine
Black high-end responsive website dream weaving template (adaptive mobile terminal)
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
Grabbing and sorting out external articles -- status bar [4]
Adapter-a technology of adaptive pre training continuous learning
How to generate rich text online
随机推荐
【无标题】数据库中一条查询SQL执行的过程
SPI communication protocol
抓包整理外篇——————状态栏[ 四]
Black high-end responsive website dream weaving template (adaptive mobile terminal)
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Computer graduation design PHP college student human resources job recruitment network
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
[solution] add multiple directories in different parts of the same word document
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
2022年版图解网络PDF
Pangolin Library: subgraph
Online reservation system of sports venues based on PHP
UE4 - how to make a simple TPS role (I) - create a basic role
技术管理进阶——什么是管理者之体力、脑力、心力
Gbase 8C database upgrade error
Genius storage uses documents, a browser caching tool
数据工程系列精讲(第四讲): Data-centric AI 之样本工程
Redis list
MySQL learning notes - subquery exercise