share my java solution!


  • 0
    C
    public class Solution {
        public int findLonelyPixel(char[][] picture) {
            if(picture==null||picture.length<0) return 0;
            
             int[] rows=new int[picture.length];
             int[] cols=new int[picture[0].length];
             for(int i=0;i<picture.length;i++){
                 for(int j=0;j<picture[0].length;j++){
                       if(picture[i][j]=='B') {
                           rows[i]++;
                           cols[j]++;
                       }
                 }
             }
             int count=0;
             for(int i=0;i<picture.length;i++){
                 for(int j=0;j<picture[0].length;j++){
                     if(picture[i][j]!='B') continue;
                     if(rows[i]==1&&cols[j]==1){
                         count++;
                     }
                 }
             }
             return count;
        }
    }
    

Log in to reply
 

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