Given a grid of integers grid, return the sum of all the numbers in it.
A grid is a table of numbers made of rows. Every row has the same number of values, one in each column. Rows are counted from the top and columns from the left, both starting at 0.
Example 1:
Input: grid = [[1, 2, 3],
[4, 5, 6]]
Output: 21
Explanation: The first row adds up to 1 + 2 + 3 = 6 and the second to 4 + 5 + 6 = 15. Together: 6 + 15 = 21.
Example 2:
Input: grid = [[-3, 4],
[5, -6]]
Output: 0
Explanation: -3 + 4 + 5 + (-6) = 0. Negative numbers make the sum smaller.
Example 3:
Input: grid = [[7]] Output: 7 Explanation: A grid with one row and one column holds a single number.
Constraints:
gridhas at least 1 row and at most 10 rows.- Every row has the same number of values, at least 1 and at most 10.
- Every value is an integer between -1000 and 1000.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
