当前位置:网站首页>剑指 Offer 29. 顺时针打印矩阵
剑指 Offer 29. 顺时针打印矩阵
2022-07-06 02:11:00 【anieoo】
原题链接;剑指 Offer 29. 顺时针打印矩阵
solution:
和螺旋矩阵一样的解法
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; //定义返回值
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;
}
};边栏推荐
- Spark accumulator
- Dynamics 365 开发协作最佳实践思考
- ftp上传文件时出现 550 Permission denied,不是用户权限问题
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- Using SA token to solve websocket handshake authentication
- Competition question 2022-6-26
- I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
- Computer graduation design PHP enterprise staff training management system
猜你喜欢

2022 edition illustrated network pdf

2022 PMP project management examination agile knowledge points (8)

It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment

【社区人物志】专访马龙伟:轮子不好用,那就自己造!

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

leetcode3、實現 strStr()

Computer graduation design PHP enterprise staff training management system

Redis如何实现多可用区?

Adapter-a technology of adaptive pre training continuous learning

Tensorflow customize the whole training process
随机推荐
MySQL index
怎么检查GBase 8c数据库中的锁信息?
Dynamics 365 开发协作最佳实践思考
论文笔记: 图神经网络 GAT
729. My schedule I / offer II 106 Bipartite graph
更换gcc版本后,编译出现make[1]: cc: Command not found
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Online reservation system of sports venues based on PHP
Using SA token to solve websocket handshake authentication
selenium 元素定位(2)
RDD creation method of spark
【机器人手眼标定】eye in hand
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
RDD partition rules of spark
【机器人库】 awesome-robotics-libraries
selenium 等待方式
Prepare for the autumn face-to-face test questions
Regular expressions: examples (1)
在线怎么生成富文本
02. Go language development environment configuration