View
반응형
문제
- 프로그래머스 연습문제- 나누어 떨어지는 숫자 배열
- https://programmers.co.kr/learn/courses/30/lessons/12910
풀이
주어진 배열을 divisor로 나누어 나머지가 0인 값만 ans배열에 넣는다.
만약 ans배열이 비어있다면, -1을 넣고 리턴한다.
코드
def solution(arr, divisor):
ans=list()
for i in range(len(arr)):
if arr[i]%divisor == 0:
ans.append(arr[i])
if ans == []:
ans=[-1]
ans.sort()
return ans
반응형
'알고리즘 > Python' 카테고리의 다른 글
[프로그래머스] 같은 숫자는 싫어 - python (0) | 2020.07.26 |
---|---|
[프로그래머스] 숫자게임 - python (0) | 2020.07.26 |
[프로그래머스] 주식가격 - python (0) | 2020.07.26 |
[프로그래머스] k번째 수 - python (0) | 2020.07.26 |
[프로그래머스] 스킬트리 - python (0) | 2020.07.26 |