[프로그래머스] 나누어 떨어지는 숫자 배열 (Level 1)

imyo·2020년 10월 7일
0

알고리즘

목록 보기
36/39
post-thumbnail

나누어 떨어지는 숫자 배열


Python Code

def solution(arr, divisor):
    answer = sorted([i for i in arr if i%divisor == 0])
    if not answer:
        answer.append(-1)
    return answer

다른 사람의 풀이

return sorted([i for i in arr if i%divisor == 0]) or [-1]

or를 사용해 한 줄로 끝내는 방법이 있었다.

profile
(●⁰౪⁰●)

0개의 댓글