반응형
Given a 2D ( nested ) list ( array, vector, .. ) of size m * n, your task is to find the sum of the minimum values in each row.
For Example:
[ [ 1, 2, 3, 4, 5 ] # minimum value of row is 1
, [ 5, 6, 7, 8, 9 ] # minimum value of row is 5
, [ 20, 21, 34, 56, 100 ] # minimum value of row is 20
]
So the function should return 26 because the sum of the minimums is 1 + 5 + 20 = 26.
Note: You will always be given a non-empty list containing positive values.
ENJOY CODING :)
Solution:
def sum_of_minimums(numbers):
return sum(map(min, numbers))
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Alternate capitalization (0) | 2022.08.23 |
---|---|
Deodorant Evaporator (0) | 2022.08.22 |
Flatten and sort an array (0) | 2022.08.20 |
Find the stray number (0) | 2022.08.19 |
5 without numbers !! (0) | 2022.08.19 |