当前位置:网站首页>LeetCode-498 - Diagonal Traversal
LeetCode-498 - Diagonal Traversal
2022-08-10 21:28:00 【z754916067】
题目


思路
- 直接遍历就行.
代码
public int[] findDiagonalOrder(int[][] mat) {
int[] ans = new int[mat.length * mat[0].length];
int index = 0;
//在matIt traverses the rows and columns inside
int row=0;
int col=0;
//Top right or bottom left 右上true 左下false
boolean flag = true;
while (row<mat.length && col<mat[0].length){
if(flag){
while (row>=0 && col<mat[0].length){
ans[index++] = mat[row--][col++];
}
col--;
row++;
//move right first
if(col+1<mat[0].length) col++;
else row++;
flag=false;
}else {
while(row<mat.length && col>=0){
ans[index++] = mat[row++][col--];
}
row--;
col++;
//Move down first
if(row+1<mat.length) row++;
else col++;
flag=true;
}
}
return ans;
}
边栏推荐
- 流程控制结构——《mysql 从入门到内卷再到入土》
- 直播课堂系统08-腾讯云对象存储和课程分类管理
- Before implementing MES management system, these three questions to consider
- Rider调试ASP.NET Core时报thread not gc-safe的解决方法
- 第14届全国大学生信息安全竞赛-创新实践能力赛
- 华为路由器旁挂引流实验(使用流策略)
- The evolution history of Go programmers
- APP application related instructions in Auto.js
- sklearn 笔记 TSNE
- 【vulhub】MySql身份认证绕过漏洞复现(CVE-2012-2122)
猜你喜欢

数据标注太昂贵?这个方法可以用有限的数据训练模型实现基于文本的ReID!

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

【PCBA方案】电子握力测试仪方案she‘ji

美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践

HighTec快捷键(Keys)设置位置

直播课堂系统08-腾讯云对象存储和课程分类管理

我的世界整合包 云服务器搭建方法(ECS)

直播课堂系统09--腾讯云点播管理模块(一)

npm‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件

apr_thread使用内存之谜
随机推荐
Floating window in Auto.js
2021年中国工业互联网安全大赛(福建省选拔赛) 暨首届福建省工业互联网创新大赛
B. Same Parity Summands
npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
根心与根轴
ACM模板笔记:八数码问题——使用BFS+康托展开打表解决
Uniapp编译后小程序的代码反编译一些思路
JS中的filter、map、reduce
LeetCode-36-Binary search tree and doubly linked list
npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
LeetCode-498-对角线遍历
Object.assign用法 以及 与$.extend的区别
web逆向之丁香园
地理探测器Geodetector软件的下载、应用与结果解读
Live Classroom System 09--Tencent Cloud VOD Management Module (1)
PROCEDURE :存储过程结构——《mysql 从入门到内卷再到入土》
美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
测试代码新的规则
D. Game With Array
Likou 221 questions, the largest square