当前位置:网站首页>1380. lucky numbers in matrices
1380. lucky numbers in matrices
2022-06-30 05:37:00 【Phoenix_ ZengHao】
subject
1380. The lucky number in the matrix
The main idea of the topic
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
Examples

Data scale

Ideas
Definition minnr[],maxxc[] Separate indication control i i i Row min and th j j j The value of the largest element in the column . Preprocessing by traversing the matrix . After processing the relevant maximum values of each row and column , Traverse every element of the matrix again m a t r i x [ i ] [ j ] matrix[i][j] matrix[i][j], If it can satisfy m a t r i x [ i ] [ j ] = = m i n n r [ i ] & & m a t r i x [ i ] [ j ] = = m a x x c [ j ] matrix[i][j]==minnr[i]\&\&matrix[i][j]==maxxc[j] matrix[i][j]==minnr[i]&&matrix[i][j]==maxxc[j], It means that the element is a lucky number , Add to answer array a n s ans ans in , Finally back to a n s ans ans.
Code
class Solution {
public:
int minnr[100],maxxc[100];
vector<int> luckyNumbers (vector<vector<int>>& matrix) {
memset(minnr,0x3f3f3f3f,sizeof(minnr));
memset(maxxc,-0x3f3f3f3f,sizeof(maxxc));
int n=matrix.size(),m=matrix[0].size();
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
minnr[i]=min(minnr[i],matrix[i][j]);
maxxc[j]=max(maxxc[j],matrix[i][j]);
}
}
vector<int>ans;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(matrix[i][j]==minnr[i]&&matrix[i][j]==maxxc[j]){
ans.push_back(matrix[i][j]);
}
}
}
return ans;
}
};
边栏推荐
- Unity C trigonometric function, right triangle corner calculation
- PyGame. Why can't I exit when I click X in the window? I can only exit when I return idle
- 聲網,站在物聯網的“土壤”裏
- Unity animator does not clip animation to play animation in segments
- Unity3d position the model, rotate, drag and zoom around the model to obtain the center point of the model
- We strongly recommend more than a dozen necessary plug-ins for idea development
- Unity publishing /build settings
- Delete the repeating elements in the sorting list (simple questions)
- Qt之QListView的简单使用(含源码+注释)
- Unit asynchronous jump progress
猜你喜欢

企事业单位源代码防泄露工作该如何进行

Unityshader learning notes - Basic Attributes

Solidity - 安全 - 重入攻击(Reentrancy)
![[learning notes] AssetBundle, xlua, hot update (use steps)](/img/59/9d9f31cfe55a908f2f0705e95ecc05.jpg)
[learning notes] AssetBundle, xlua, hot update (use steps)

旋转框目标检测mmrotate v0.3.1入门

Intellj idea jars projects containing external lib to other project reference methods - jars

VFPBS上传EXCEL并保存MSSQL到数据库中

VFPBS在IIS下调用EXCEL遇到的Access is denied

【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点

14x1.5cm竖向标签有点难,VFP调用BarTender来打印
随机推荐
Unity3d get screen width and height
聲網,站在物聯網的“土壤”裏
C. Divan and bitwise operations
[note] usage model tree of the unity resource tree structure virtualizingtreeview
Unity obtains serial port data
Rotating box target detection mmrotate v0.3.1 getting started
Unity ugui text value suspended enlarged display add text background
Shopping list--
[Blue Bridge Road -- bug free code] analysis of AT24C02 storage code
Unity3d- use animator and code to control task walking
Unity scroll view element drag and drop to automatically adsorb centering and card effect
抓取手机端变体组合思路设想
Access is denied encountered when vfpbs calls excel under IIS
mmcv常用API介绍
Expansion method of unity scanning circle
Display steerable 3D model in front of unity UI
Assembly learning tutorial: accessing memory (3)
Video summary of my station B
声网,站在物联网的“土壤”里
Use of OpenCL thread algebra library viennacl