2732. 找到矩阵中的好子集
题目链接:2732. 找到矩阵中的好子集
代码如下:
//参考:https://leetcode.cn/problems/find-a-good-subset-of-the-matrix/solutions/2305490/xiang-xi-fen-xi-wei-shi-yao-zhi-duo-kao-mbl6a
class Solution
{
public:
vector<int> goodSubsetofBinaryMatrix(vector<vector<int>>& grid)
{
unordered_map<int,int> mask_to_idx;
for(int i=0;i<grid.size();i++)
{
int mask=0;
for(int j=0;j<grid[i].size();j++)
{
mask|=grid[i][j]<<j;
}
if(mask==0) {return {i};}
mask_to_idx[mask]=i;
}
for(auto[x,i]:mask_to_idx)
{
for(auto [y,j]:mask_to_idx)
{
if((x&y)==0)
{
return {min(i,j),max(i,j)};
}
}
}
return {};
}
};