25ms Java beats 100%


  • 0
    W
    public int findLonelyPixel(char[][] picture) {
      int count = 0, rowCount[][] = new int[picture.length][2], colCount[] = new int[picture[0].length];
      for (int row = 0; row < picture.length; row++)
        for (int col = 0; col < picture[0].length; col++)
          if (picture[row][col] == 'B') {
            rowCount[row][0]++;
            rowCount[row][1] = col;
            colCount[col]++;
          }
      for (int row = 0; row < picture.length; row++)
        if (rowCount[row][0] == 1 && colCount[rowCount[row][1]] == 1) count++;
      return count;
    }

Log in to reply
 

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