当前位置:网站首页>1424. 对角线遍历 II
1424. 对角线遍历 II
2022-06-29 08:45:00 【Mr Gao】
1424. 对角线遍历 II
给你一个列表 nums ,里面每一个元素都是一个整数列表。请你依照下面各图的规则,按顺序返回 nums 中对角线上的整数。
示例 1:
输入:nums = [[1,2,3],[4,5,6],[7,8,9]]
输出:[1,4,2,7,5,3,8,6,9]

示例 3:
输入:nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]
输出:[1,4,2,5,3,8,6,9,7,10,11]
示例 4:
输入:nums = [[1,2,3,4,5,6]]
输出:[1,2,3,4,5,6]
解题代码如下:
/** * Note: The returned array must be malloced, assume caller calls free(). */
int* findDiagonalOrder(int** nums, int numsSize, int* numsColSize, int* returnSize){
int i;
int n=numsSize;
int colmax=0;
for(i=0;i<numsSize;i++){
if(numsColSize[i]>colmax){
colmax=numsColSize[i];
}
}
printf("n %d %d",n,colmax);
int *re=(int *)malloc(sizeof(int)*(n*colmax+5));
int size=0;
for(i=0;i<n;i++){
re[size++]=nums[i][0];
int x=0;
int y=i;
while(x+1<=i&&y-1>=0){
x=x+1;
y=y-1;
if(numsColSize[y]>x){
re[size++]=nums[y][x];
}
}
}
for(i=1;i<colmax;i++){
if(numsColSize[n-1]>i)
re[size++]=nums[n-1][i];
// printf("df");
int x=i;
int y=n-1;
while(x+1<=colmax-1&&y-1>=0){
// printf("%d %d",x+1,y-1);
x=x+1;
y=y-1;
if(numsColSize[y]>x){
re[size++]=nums[y][x];
}
}
}
*returnSize=size;
return re;
}
边栏推荐
- CMD enter virtual machine
- In the future of Business Intelligence BI, how do you view the ai+bi model?
- Twinmotion beginner tutorial
- Pytorch summary learning series - broadcast mechanism
- UE4 blueprint modify get a copy in array to reference
- Jar package and war package
- Self cultivation (XXI) servlet life cycle, service method source code analysis, thread safety issues
- Gd32f4xx Ethernet Chip (ENC28J60) Drive transplantation
- 长安链数据存储介绍及Mysql存储环境搭建
- Reading notes on how to connect the network - Web server request and response (IV)
猜你喜欢
![[target detection] | indicator a probabilistic challenge for object detection](/img/82/7b830d44bed7b1509cb0cdfed88e3e.png)
[target detection] | indicator a probabilistic challenge for object detection

UE4 VS的Visual Assist插件设置

UE4 蓝图修改Array 中Get a copy 为 reference

UE4 去掉材质中Mask透明白边

Mysql配置主从数据库

LFFD:一种用于边缘检测的轻量化快速人脸检测器

What is the difference between hyperconverged architecture and traditional architecture?

# 《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)

SSD改进CFENet

数据处理时代,数据质量建设才是企业的生存之道
随机推荐
Augfpn: amélioration de l'apprentissage des caractéristiques à plusieurs échelles pour la détection des cibles
Pytorch learning summary - memory cost of operation
Augfpn: improved multiscale feature learning for target detection
pytorch学习总结—运算的内存开销
Simplicity studio does not recognize the new JLINK V9 solution
Simplicity Studio无法识别新买的JLink v9解决方法
Wechat applet latest canvas2d handwritten signature
Wechat applet project: wechat applet page layout
Pytorch summary learning series - data manipulation
Simple use of promise method
长安链数据存储介绍及Mysql存储环境搭建
数据处理时代,数据质量建设才是企业的生存之道
深卷积神经网络时代的目标检测研究进展
Training kernel switching using GPU
[target detection] | indicator a probabilistic challenge for object detection
通识篇:原型设计的认知,设计及最佳实践
第十二章 信号(二)- 生产者消费者示例
ServerApp. iopub
UE4 在4.20-23版本安装Datasmith插件
What is hyperfusion? What is the difference with traditional architecture