当前位置:网站首页>Lucky numbers in the matrix
Lucky numbers in the matrix
2022-06-26 14:09:00 【fe11953264】
subject
To give you one m * n Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .
Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :
The smallest of all elements in the same row
The largest of all elements in the same column
break And continue Comparison of
break You can only jump out of a loop . When there are multiple nested loops ,break Can only jump out of “ The parcel ” Its innermost layer of circulation , Can't jump out of all loops at once .
continue It's very simple , Its function is to end this cycle , That is, skip the following unexecuted statements in the loop body , Then, it is determined whether to execute the cycle next time .
Code
int* luckyNumbers (int** matrix, int matrixSize, int* matrixColSize, int* returnSize){
int *adc=(int*)malloc(sizeof(int) * matrixSize * matrixColSize[0]);
int shu = 0;
for(int i = 0 ; i < matrixSize ; i++){
for(int y = 0 ; y < matrixColSize[0] ; y++){
bool max1 = true , min1 = true;
for(int k = 0 ; k < matrixColSize[0] ; k++){ // The smallest... In the column
if(matrix[i][k] < matrix[i][y]){
min1 = false;
break;
}
}
if(!min1){ // Wrong column , Return to find a new value
continue;
}
for(int n = 0 ; n < matrixSize ; n++){ // Maximum in row
if(matrix[n][y] > matrix[i][y]){
max1 = false;
break;
}
}
if(max1){
adc[shu++] =matrix[i][y];
}
}
}
*returnSize = shu;
return adc;
}
边栏推荐
猜你喜欢

9 articles, 6 interdits! Le Ministère de l'éducation et le Ministère de la gestion des urgences publient et publient conjointement neuf règlements sur la gestion de la sécurité incendie dans les établ

ThreadLocal giant pit! Memory leaks are just Pediatrics

去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程

Zero basics of C language lesson 8: Functions

Included angle of 3D vector

Gartner 2022 Top Strategic Technology Trends Report

Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital

嵌入式virlog代码运行流程

Nexys A7开发板资源使用技巧

永远不要使用Redis过期监听实现定时任务!
随机推荐
Es snapshot based data backup and restore
2021-10-09
9 articles, 6 interdits! Le Ministère de l'éducation et le Ministère de la gestion des urgences publient et publient conjointement neuf règlements sur la gestion de la sécurité incendie dans les établ
程序员必备,一款让你提高工作效率N倍的神器uTools
永远不要使用Redis过期监听实现定时任务!
Hands on data analysis unit 3 model building and evaluation
Range of types
How to check if a text field is empty or not in swift
What is the use of index aliases in ES
[proteus simulation] Arduino uno key start / stop + PWM speed control DC motor speed
Linear basis
First k large XOR value problem
Wechat applet Registration Guide
ThreadLocal巨坑!内存泄露只是小儿科...
古瑞瓦特冲刺港交所上市:创下“多个第一”,获IDG资本9亿元投资
Firewall introduction
Zero basics of C language lesson 7: break & continue
"Scoi2016" delicious problem solution
Wechat applet - bind and prevent event bubble catch
Postman自动化接口测试