Simple C++ 56ms 99.62%


  • 0
    class Solution {
    public:
        int findLonelyPixel(vector<vector<char>>& picture) {
            if(picture.empty()) return 0;
            int m = picture.size(), n = picture[0].size();
            int count = 0;
            for(int i = 0; i < m; i++){
                bool B = true;
                for(int j = 0; j < n && B; j++){
                    if(picture[i][j] == 'B'){
                        B = false;
                        int r = 0, c = j + 1;
                        for(; r < m; r++) if(r != i && picture[r][j] == 'B') break;
                        for(; c < n; c++) if(picture[i][c] == 'B') break;
                        if(r == m && c == n) count++;
                    }
                }
            }
            return count;
        }
    };
    

Log in to reply
 

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