C++ easy O(mn) solution


  • 0
    M
        int findLonelyPixel(vector<vector<char>>& picture) {
            int res=0;
            vector<int> row(picture.size(), 0), col(picture[0].size(), 0);
            for(int i=0;i<picture.size();i++) {
                for(int j=0;j<picture[0].size();j++) {
                    if(picture[i][j]=='B') row[i]++, col[j]++;
                }
            }
            for(int i=0;i<picture.size();i++) {
                if(row[i]>1) continue;
                for(int j=0;j<picture[0].size();j++) {
                    if(col[j]>1) continue;
                    if(picture[i][j]=='B') res++;
                }
            }
            return res;
        }

Log in to reply
 

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