C++ O(nm), O(m+n) space


  • 0
    T

    My solution:

    class Solution {
    public:
        int findLonelyPixel(vector<vector<char>>& picture) 
            map<int,int> r;
            map<int,int> v;
            for (int i=0;i<picture.size();i++)
                for (int j=0;j<picture[i].size();j++)
                    if (picture[i][j]=='B')
                    {
                        r[i]++;
                        v[j]++;
                    }
            int sr=0,sv=0;
            for (auto&& c:r)
                if (c.second==1) sr++;
            for (auto&& c:v)
                if(c.second==1) sv++;
            return min(sr,sv);
        }
    };
    

Log in to reply
 

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