Given a grid of integers grid and an integer target, return how many cells of the grid are equal to target.
A grid is an array of rows, and each row is an array of integers.
Example 1:
Input: grid = [ [1, 2, 3], [4, 2, 6], [2, 8, 2] ], target = 2 Output: 4 Explanation: 2 appears once in the first row, once in the second row and twice in the third row: 1 + 1 + 2 = 4.
Example 2:
Input: grid = [ [-1, 5], [5, -1] ], target = -1 Output: 2 Explanation: The two cells with -1 are in different rows, and each one counts.
Example 3:
Input: grid = [ [7, 8, 9] ], target = 4 Output: 0 Explanation: No cell is equal to 4.
Constraints:
gridhas at least 1 row and 1 column, and every row has the same number of values.- Every value and
targetis an integer between -1000 and 1000; they can be negative.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
