반응형
Description:
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array.
For example:
solution([1,2,3,10,5]) # should return [1,2,3,5,10]
solution(None) # should return []
Solution:
1. If the 'nums' array is empty, an empty array is returned.
2. If the 'nums' array is not empty, the elements are sorted and returned.
def solution(nums):
return sorted(nums or [])
Logical operators can also be used for function parameters.
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Sum of two lowest positive integers (0) | 2022.04.19 |
---|---|
Square Every Digit (0) | 2022.04.18 |
Regex validate PIN code (0) | 2022.04.16 |
Get the mean of an array (0) | 2022.04.15 |
Sum of Odd Cubed Numbers (0) | 2022.04.14 |