Given a 3×3 grid of integers grid, return the number in its center: the one in the middle row and the middle column.
A grid is a table of numbers made of rows. This one has 3 rows, and every row has 3 numbers, one in each column. Rows and columns are counted from 0, so the middle row is row 1 and the middle column is column 1.
Example 1:
Input: grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Output: 5 Explanation: The middle row is [4, 5, 6], and the number in its middle column is 5.
Example 2:
Input: grid = [[0, 0, 0], [0, 7, 0], [0, 0, 0]] Output: 7 Explanation: 7 is in row 1, column 1: the center of the grid.
Example 3:
Input: grid = [[9, 8, 7], [6, -5, 4], [3, 2, 1]] Output: -5 Explanation: The center can be any number, a negative one too.
Constraints:
gridhas exactly 3 rows, and every row has exactly 3 numbers.- Every number is an integer between -1000 and 1000.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
