当前位置:网站首页>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;
}
};边栏推荐
- Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
- RDD conversion operator of spark
- Jisuanke - t2063_ Missile interception
- 论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
- SSM 程序集
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- 我把驱动换成了5.1.35,但是还是一样的错误,我现在是能连成功,但是我每做一次sql操作都会报这个
- A basic lintcode MySQL database problem
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- 模板_求排列逆序对_基于归并排序
猜你喜欢

leetcode3、實現 strStr()

Computer graduation design PHP part-time recruitment management system for College Students

Leetcode3, implémenter strstr ()

Initial understanding of pointer variables

好用的 JS 脚本

Computer graduation design PHP enterprise staff training management system

How to improve the level of pinduoduo store? Dianyingtong came to tell you

Redis如何实现多可用区?

安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3

Extracting key information from TrueType font files
随机推荐
PHP campus financial management system for computer graduation design
Redis daemon cannot stop the solution
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
Derivation of Biot Savart law in College Physics
Thinking about the best practice of dynamics 365 development collaboration
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
Bidding promotion process
Using SA token to solve websocket handshake authentication
02. Go language development environment configuration
Bigder:34/100 面试感觉挺好的,没有收到录取
【机器人手眼标定】eye in hand
vs code保存时 出现两次格式化
Use Scrollview and tabhost to realize vertical scrollbars and tabs
模板_快速排序_双指针
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
剑指 Offer 29. 顺时针打印矩阵
模板_求排列逆序对_基于归并排序
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
Executing two identical SQL statements in the same sqlsession will result in different total numbers