当前位置:网站首页>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;
}
边栏推荐
- Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
- Wechat applet custom multi selector
- UE4 VS的Visual Assist插件设置
- UE4 compile a single file (VS and editor start respectively)
- 基於PyQt5和Qt Designer的簡易加法計算器的制作
- The difference between cokkie and session
- 云管理平台:9大开源云管理平台(CMP)
- Wechat applet latest canvas2d handwritten signature
- Understanding of singleton mode
- UE4 在4.20-23版本安装Datasmith插件
猜你喜欢

kdevelop新建工程

Data governance: data standard management (Part III)

Introduction to Chang'an chain data storage and construction of MySQL storage environment

ThinkPHP 6 uses mongodb

Laravel 8 enables the order table to be divided by month level

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

Wechat applet user refuses to authorize geographic location information and calls up the authorization window again

Research progress of target detection in the era of deep convolutional neural network

商业智能BI的未来,如何看待AI+BI这种模式?

Mongodb persistence
随机推荐
你必须知道的23个最有用的Elasticseaerch检索技巧
Reading notes on how to connect the network - Web server request and response (V)
Find the most repeated element in the string
A 2.5D Cancer Segmentation for MRI Images Based on U-Net
证券账号开户安全吗?是靠谱的吗?
Cloud management platform: openstack architecture design and detailed interpretation
云管理平台:9大开源云管理平台(CMP)
Recursive RBAC menu level display infinite classification
Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear
官方stm32芯片包下载地址 stm32f10x stm32f40x下载
Go deep into RC, RS, daemonset and statefulset (VII)
遍历vector容器中的对象的方式
Simplicity studio does not recognize the new JLINK V9 solution
Mysql database and table splitting strategy and application scenarios
UE4 插件报错 Cannot open include file: ‘ModuleManager.h‘解决
ISO16000-9建筑产品和家具中挥发性有机物的测试
Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
UE4 材质UV纹理不随模型缩放拉伸
Difference between factory mode and strategy mode
LC236. 二叉树的最近公共祖先