当前位置:网站首页>1424. diagonal traversal II
1424. diagonal traversal II
2022-06-29 09:44:00 【Mr Gao】
1424. Diagonal traversal II
Here's a list nums , Each element is a list of integers . Please follow the rules of the following pictures , Go back to... In order nums Integer on diagonal in .
Example 1:
Input :nums = [[1,2,3],[4,5,6],[7,8,9]]
Output :[1,4,2,7,5,3,8,6,9]

Example 3:
Input :nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]
Output :[1,4,2,5,3,8,6,9,7,10,11]
Example 4:
Input :nums = [[1,2,3,4,5,6]]
Output :[1,2,3,4,5,6]
The solution code is as follows :
/** * 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;
}
边栏推荐
- Data visualization: the significance of data visualization
- 数据可视化:数据可视化的意义
- Mysql配置主从数据库
- After aikuai is installed or reset, the PC or mobile terminal cannot obtain IP
- 1424. 对角线遍历 II
- ISO16000-9建筑产品和家具中挥发性有机物的测试
- Data warehouse: layered architecture of Finance / banking
- # 《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)
- Mongodb persistence
- Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
猜你喜欢

Gd32f4xx Ethernet Chip (ENC28J60) Drive transplantation

基于keil5自动配置stm32f103标准库的官网freertos移植

CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION

How to do unit test well

MATLAB小技巧(21)矩阵分析--偏最小二乘回归

基于stm32标准库独立按键的多按键状态机的实现

基于PyQt5和Qt Designer的简易加法计算器的制作

Print service IP setting scheme

Data visualization: the four quadrants of data visualization teach you to correctly apply icons

你知道BFD是什么吗?一文详解BFD协议原理及使用场景
随机推荐
Closed door cultivation (24) shallow understanding of cross domain problems
Data visualization: the significance of data visualization
1.4 机器学习方法之回归问题
Construction and use of Changan chain go language smart contract environment
数据治理:元数据管理(第二篇)
Kicad learning notes - shortcut keys
UE4 plug-in reports an error cannot open include file: 'modulemanager H 'resolve
Iso16000-9 testing of volatile organic compounds in building products and furniture
Twinmotion 初学者教程
KiCad学习笔记--快捷键
数据治理:数据标准管理(第三篇)
Pytorch summary learning series - data manipulation
如何将谷歌浏览器设置为默认浏览器
股票炒股账号开户安全吗?是靠谱的吗?
Western Polytechnic University, one of the "seven national defense schools", was attacked by overseas networks
ISO16000-9建筑产品和家具中挥发性有机物的测试
你知道BFD是什么吗?一文详解BFD协议原理及使用场景
Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
After aikuai is installed or reset, the PC or mobile terminal cannot obtain IP
Closed training (25) basic web security