Given a grid of integers grid and an integer target, find the first cell equal to target and return its position as a Vec of two integers: its row and its column.
A grid is an array of rows, and each row is an array of integers. Rows are numbered from 0, top to bottom, and columns from 0, left to right.
"First" means in reading order: the top row from left to right, then the next row, and so on. If no cell is equal to target, return [-1, -1].
Example 1:
Input: grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ], target = 6 Output: [1, 2] Explanation: 6 is in row 1 (the second row) and column 2 (the third column).
Example 2:
Input: grid = [ [5, 1], [1, 5] ], target = 1 Output: [0, 1] Explanation: 1 appears twice. Reading row by row, the 1 in row 0, column 1 comes before the 1 in row 1, column 0.
Example 3:
Input: grid = [ [4, 4], [4, 4] ], target = 3 Output: [-1, -1] Explanation: No cell is equal to 3.
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.
