Count Servers that Communicate(C++统计参与通信的服务器)

(1)行数目,列数目

(2)使用map消除重复

class Solution {
private:
    int count=0;
public:
    int countServers(vector>& grid) {
        int m=grid.size(),n=grid[0].size();
        unordered_map mp;
        int first=0,second=0;
        //行
        for(int i=0;i1) mp[to_string(first)+'_'+to_string(second)]=1;
            count=0;
        }

        //列
        for(int i=0;i1) mp[to_string(first)+'_'+to_string(second)]=1;
            count=0;
        }


        return mp.size();
    }
};

 

你可能感兴趣的:(C++,LeetCode,c++,leetcode,矩阵,map)