C++ time O(nm) space O(n+m) 100%defeated


  • 0
    F

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

    my_blog


  • 0
    F

    Does anybody knows how to put code with indent。。。。


Log in to reply
 

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