Beats 100% simple java solution


  • 0

    Pretty straight-forward, perhaps I lucked out on the time of execution on the OJ (30ms)

    
        public int findLonelyPixel(char[][] picture) {
            if (picture == null || picture.length == 0 || picture[0].length == 0) return 0;
            
            int m = picture.length, n = picture[0].length;
            int[] rows = new int[m], cols = new int[n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (picture[i][j] == 'B') {
                        rows[i]++; cols[j]++;
                    }
                }
            }
            int lonely = 0;
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (picture[i][j] == 'B' && rows[i] == 1 && cols[j] == 1) {
                        lonely++;
                    }
                }
            }
            return lonely;
        }
    

Log in to reply
 

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