[LeetCode] Lonely Pixel II 孤独的像素之二

Given a picture consisting of black and white pixels, and a positive integer N, find the number of black pixels located at some specific row R and column C that align with all the following rules:

  1. Row R and column C both contain exactly N black pixels.
  2. For all rows that have a black pixel at column C, they should be exactly the same as row R

The picture is represented by a 2D char array consisting of ‘B‘ and ‘W‘, which means black and white pixels respectively.

Example:

Input:
[[‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘B‘, ‘W‘],
 [‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘B‘, ‘W‘],
 [‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘B‘, ‘W‘],
 [‘W‘, ‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘W‘]] 

N = 3
Output: 6
Explanation: All the bold ‘B‘ are the black pixels we need (all ‘B‘s at column 1 and 3).
        0    1    2    3    4    5         column index
0    [[‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘B‘, ‘W‘],
1     [‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘B‘, ‘W‘],
2     [‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘B‘, ‘W‘],
3     [‘W‘, ‘W‘, ‘B‘, ‘W‘, ‘B‘, ‘W‘]]
row index

Take ‘B‘ at row R = 0 and column C = 1 as an example:
Rule 1, row R = 0 and column C = 1 both have exactly N = 3 black pixels.
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.

Note:

    1. The range of width and height of the input 2D array is [1,200].

s

时间: 2024-10-25 06:00:53

[LeetCode] Lonely Pixel II 孤独的像素之二的相关文章

[LeetCode] Lonely Pixel I 孤独的像素之一

Given a picture consisting of black and white pixels, find the number of black lonely pixels. The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and white pixels respectively. A black lonely pixel is character

533. Lonely Pixel II

Given a picture consisting of black and white pixels, and a positive integer N, find the number of black pixels located at some specific row Rand column C that align with all the following rules: Row R and column C both contain exactly N black pixels

LeetCode 90. Subsets II (子集合之二)

Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example,If nums = [1,2,2], a solution is: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] 题目标签:Arr

[LeetCode] Contains Duplicate II 包含重复值之二

Given an array of integers and an integer k, return true if and only if there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. 这道题是之前那道Contains Duplicate 包含重复值的延伸,不同之处在于那道题只要我们

[LeetCode] Single Number II 单独的数字之二

Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 这道题是之前那道单独的数字的延伸,那道题的解法就比较独特,是利用计算机按位储

[LeetCode] Unique Paths II 不同的路径之二

Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middl

[LeetCode] Sentence Similarity II 句子相似度之二

Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar. For example, words1 = ["great", "acting", "skills"] and words2 = [&

LeetCode 531. Longly Pixel I (孤独的像素之一) $

Given a picture consisting of black and white pixels, find the number of black lonely pixels. The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and white pixels respectively. A black lonely pixel is character

LeetCode --- 90. Subsets II

题目链接:Subsets II Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,2]