Language/Python

2021 - 05 - 01, Python 프로그래머스 연습문제 :: 나누어 떨어지는 숫자 배열

Cs.Woo 2021. 5. 3. 02:50

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

def solution(arr, divisor):
    new_arr = []
    depth = len(arr)
    for i in range(0,depth):
        if arr[i] % divisor == 0:
            new_arr.append(arr[i]) 
    if len(new_arr) == 0:
        new_arr.append(-1)
    return sorted(new_arr)