반응형
You get an array of numbers, return the sum of all of the positives ones.
Example [1,-4,7,12]
=> 1 + 7 + 12 = 20
Note: if there is nothing to sum, the sum is default to 0.
Solution:
def positive_sum(arr):
return sum(map(remove_negative, arr))
def remove_negative(i: int):
return i if i >= 0 else 0
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0926. Merge two sorted arrays into one (0) | 2022.09.26 |
---|---|
0925. Thinkful - Logic Drills: Traffic light (0) | 2022.09.25 |
0923. Sum of differences in array (0) | 2022.09.23 |
0922. Love vs friendship (0) | 2022.09.22 |
0921. Sum without highest and lowest number (0) | 2022.09.21 |