当前位置:网站首页>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;
}
边栏推荐
- pytorch总结学习系列-数据操作
- 股票炒股账号开户安全吗?是靠谱的吗?
- LC236. 二叉树的最近公共祖先
- UE4 material UV texture does not stretch with model scale
- How to do unit test well
- Lffd: a lightweight fast face detector for edge detection
- Pytorch summary learning series - data manipulation
- Wechat applet user refuses to authorize geographic location information and calls up the authorization window again
- 深入RC、RS、DaemonSet、StatefulSet(七)
- What is the difference between hyperconverged architecture and traditional architecture?
猜你喜欢

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

YOLO Nano:一种高度紧凑的只看一次的卷积神经网络用于目标检测

UE4 animation redirection

Print service IP setting scheme

Keras to tf Vgg19 input in keras_ shape

【目标检测】|指标 A probabilistic challenge for object detection

easyexecl导出100万行execl报字体错误的解决办法

UE4 在4.20-23版本安装Datasmith插件

如何将谷歌浏览器设置为默认浏览器
![[target detection] | indicator a probabilistic challenge for object detection](/img/82/7b830d44bed7b1509cb0cdfed88e3e.png)
[target detection] | indicator a probabilistic challenge for object detection
随机推荐
Redo after JS rotation view (longer full version, can be run)
Understanding of singleton mode
Wechat applet custom multi selector
Modify EXIF information
LeetCode刷题——泰波那契数列
Matlab tips (21) matrix analysis -- partial least squares regression
Wechat applet user refuses to authorize geographic location information and calls up the authorization window again
UE4 blueprint modify get a copy in array to reference
【NOI模拟赛】为NOI加点料(重链剖分,线段树)
Have you done the network security "physical examination" this year?
Mac mysql数据库基本操作
train_ on_ Batch save the image of the loss function change
Wechat applet opens file stream
深卷积神经网络时代的目标检测研究进展
UE4 动画重定向
云管理平台:9大开源云管理平台(CMP)
ServerApp. iopub
Professional structure record
用户级线程和内核级线程
KiCad学习笔记--快捷键