Java Solution beat 100%


  • 0
    L
    public class Solution {
        public int findLonelyPixel(char[][] picture) {
            int m = picture.length;
            if(m==0) return 0;
            int n = picture[0].length;
             //save only have one 'B' rows with the column index of 'B'
            List<Integer> rowBlank = new ArrayList<>(); 
            int[] colBlank = new int[n];
            for(int i=0; i<m; i++){
                int count = 0, pos = 0;
                for(int j=0; j<n; j++){
                    if(picture[i][j] == 'B'){
                        count++;
                        pos = j;
                        colBlank[j]++;
                    }
                }
                if(count==1) rowBlank.add(pos);
            }
            int res = 0;
            for(int pos : rowBlank){
                if(colBlank[pos] == 1) res++;
            }
            return res;
        }
    }
    

Log in to reply
 

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