Given a grid of integers grid, return an ArrayList with the sum of each row, in the same order as the rows.
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: [6, 15]
Explanation: Row 0 adds up to 1 + 2 + 3 = 6 and row 1 to 4 + 5 + 6 = 15.
Example 2:
Input: grid = [[-1, -2],
[-3, -4],
[5, 5]]
Output: [-3, -7, 10]
Explanation: One sum per row, top to bottom. A row of negative numbers has a negative sum.
Example 3:
Input: grid = [[3],
[1],
[4]]
Output: [3, 1, 4]
Explanation: Every row has a single value, so each row's sum is that value.
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
