Leetcode Problem 531. Lonely Pixel I

531. Lonely Pixel I

Leetcode Solutions

Counting with Arrays

  1. Initialize two arrays, rowCount and columnCount, to store the count of black pixels in each row and column respectively.
  2. Iterate over each cell in the matrix. For each black pixel at position (i, j), increment rowCount[i] and columnCount[j] by 1.
  3. Initialize a variable answer to store the count of lonely black pixels.
  4. Iterate over each cell in the matrix again. For each black pixel at position (i, j), if rowCount[i] and columnCount[j] are both equal to 1, increment answer by 1.
  5. Return the value of answer.
UML Thumbnail

Space Optimized Counting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...