|
3 | 3 | import java.util.HashMap;
|
4 | 4 | import java.util.Map;
|
5 | 5 |
|
6 |
| -/** |
7 |
| - * 533. Lonely Pixel II |
8 |
| - * |
9 |
| - * Given a picture consisting of black and white pixels, and a positive integer N, |
10 |
| - * find the number of black pixels located at some specific row R and column C that align with all the following rules: |
11 |
| -
|
12 |
| - Row R and column C both contain exactly N black pixels. |
13 |
| - For all rows that have a black pixel at column C, they should be exactly the same as row R |
14 |
| - The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and white pixels respectively. |
15 |
| -
|
16 |
| - Example: |
17 |
| - Input: |
18 |
| - [['W', 'B', 'W', 'B', 'B', 'W'], |
19 |
| - ['W', 'B', 'W', 'B', 'B', 'W'], |
20 |
| - ['W', 'B', 'W', 'B', 'B', 'W'], |
21 |
| - ['W', 'W', 'B', 'W', 'B', 'W']] |
22 |
| -
|
23 |
| - N = 3 |
24 |
| - Output: 6 |
25 |
| - Explanation: All the bold 'B' are the black pixels we need (all 'B's at column 1 and 3). |
26 |
| - 0 1 2 3 4 5 column index |
27 |
| - 0 [['W', 'B', 'W', 'B', 'B', 'W'], |
28 |
| - 1 ['W', 'B', 'W', 'B', 'B', 'W'], |
29 |
| - 2 ['W', 'B', 'W', 'B', 'B', 'W'], |
30 |
| - 3 ['W', 'W', 'B', 'W', 'B', 'W']] |
31 |
| - row index |
32 |
| -
|
33 |
| - Take 'B' at row R = 0 and column C = 1 as an example: |
34 |
| - Rule 1, row R = 0 and column C = 1 both have exactly N = 3 black pixels. |
35 |
| - Rule 2, the rows have black pixel at column C = 1 are row 0, row 1 and row 2. They are exactly the same as row R = 0. |
36 |
| -
|
37 |
| - Note: |
38 |
| - The range of width and height of the input 2D array is [1,200]. |
39 |
| - */ |
40 | 6 | public class _533 {
|
41 | 7 | public static class Solution1 {
|
42 | 8 | /**
|
|
0 commit comments