当前位置:网站首页>剑指 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;
}
};
边栏推荐
- 【机器人手眼标定】eye in hand
- How does redis implement multiple zones?
- 更改对象属性的方法
- Using SA token to solve websocket handshake authentication
- 1. Introduction to basic functions of power query
- [robot library] awesome robots Libraries
- Text editing VIM operation, file upload
- SQL statement
- [flask] official tutorial -part2: Blueprint - view, template, static file
- The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
猜你喜欢
SQL statement
2022 edition illustrated network pdf
selenium 等待方式
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
Numpy array index slice
Virtual machine network, networking settings, interconnection with host computer, network configuration
Computer graduation design PHP animation information website
Formatting occurs twice when vs code is saved
Computer graduation design PHP enterprise staff training management system
[flask] official tutorial -part2: Blueprint - view, template, static file
随机推荐
RDD partition rules of spark
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
[depth first search] Ji Suan Ke: Betsy's trip
PHP campus movie website system for computer graduation design
Shutter doctor: Xcode installation is incomplete
Campus second-hand transaction based on wechat applet
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
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
ftp上传文件时出现 550 Permission denied,不是用户权限问题
Unity learning notes -- 2D one-way platform production method
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
1. Introduction to basic functions of power query
leetcode-两数之和
Text editing VIM operation, file upload
Regular expressions: examples (1)
Leetcode3. Implement strstr()
leetcode3、實現 strStr()
General process of machine learning training and parameter optimization (discussion)
TrueType字体文件提取关键信息
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor