C++ easy to understand


  • 0
    B

    class Solution {
    public:
    int findLonelyPixel(vector<vector<char>>& picture) {
    int m = picture.size();
    int n = picture[0].size();
    int count = 0;
    vector<int> row(m,0);
    vector<int> line(n,0);
    for(int i=0; i<m; ++i)
    for(int j=0; j<n; ++j)
    if(picture[i][j] == 'B')
    {
    row[i]++;
    line[j]++;
    count++;
    }
    for(int i=0; i<m; ++i)
    if(row[i] > 1)
    count -= row[i];
    for(int j=0; j<n; ++j)
    if(line[j] > 1)
    count -= line[j];
    for(int i=0; i<m; ++i)
    for(int j=0; j<n; ++j)
    if(row[i] > 1 && line[j] > 1 && picture[i][j] == 'B')
    count++;
    return count;
    }
    };


Log in to reply
 

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