当前位置:网站首页>剑指 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;
}
};边栏推荐
- TrueType字体文件提取关键信息
- D22:indeterminate equation (indefinite equation, translation + problem solution)
- 2022 edition illustrated network pdf
- [width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
- Multi function event recorder of the 5th National Games of the Blue Bridge Cup
- Redis string type
- 01. Go language introduction
- Computer graduation design PHP animation information website
- How to improve the level of pinduoduo store? Dianyingtong came to tell you
- How to set an alias inside a bash shell script so that is it visible from the outside?
猜你喜欢

Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns

Campus second-hand transaction based on wechat applet

Extracting key information from TrueType font files

1. Introduction to basic functions of power query

Overview of spark RDD

leetcode3、實現 strStr()

SQL statement

Jisuanke - t2063_ Missile interception

Computer graduation design PHP college student human resources job recruitment network

Multi function event recorder of the 5th National Games of the Blue Bridge Cup
随机推荐
SSM 程序集
Redis list
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
RDD creation method of spark
2 power view
729. My schedule I / offer II 106 Bipartite graph
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()
Grabbing and sorting out external articles -- status bar [4]
抓包整理外篇——————状态栏[ 四]
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
genius-storage使用文档,一个浏览器缓存工具
Install redis
数据工程系列精讲(第四讲): Data-centric AI 之样本工程
通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
Social networking website for college students based on computer graduation design PHP
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
TrueType字体文件提取关键信息
How to improve the level of pinduoduo store? Dianyingtong came to tell you
在线怎么生成富文本