C++ 29ms


  • 0
    P
    class Solution {
    public:
        int findBlackPixel(vector<vector<char>>& picture, int N) {
            int m = picture.size(), n = picture[0].size();
            vector<int> col(n);
            
            map<vector<int>, int> m2;
            
            for (int i = 0; i < m; ++i) {
                vector<int> colpos;
                int cnt = 0;
                for (int j = 0; j < n; ++j) {
                    if (picture[i][j] == 'B') {
                        colpos.push_back(j);
                        ++cnt;
                        ++col[j];
                    }
                }
                if (cnt == N) ++m2[colpos];
            }
            int cnt = 0;
            for (auto& a: m2) {
                if (a.second == N) {
                    for (auto& b: a.first) {
                        if (col[b] == N) cnt += N;
                    }
                }
            }
            return cnt;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.