Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 안드로이드
- 코테
- Flutter
- 분할정복
- cos pro 1급
- android
- codingtest
- C++
- vuejs
- 코드품앗이
- cos
- 동적계획법과최단거리역추적
- cos pro
- 안드로이드스튜디오
- BAEKJOON
- 백준
- DART
- 코딩테스트
- django
- Python
- DFS와BFS
- 알고리즘
- 파이썬
- DFS
- Vue
- Algorithm
- AndroidStudio
- issue
- 동적계획법
- 개발
Archives
- Today
- Total
Development Artist
[COS Pro 1급, Python] 6차 3번 : 큰수와 작은수의 차이 본문
728x90
반응형
문제 유형
코딩
난이도
normal
Note
1. combination(조합) 으로 해결.
2. for문을 돌면서 min과 max를 구해서 빼고 결과를 answer에 업데이트.
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
import itertools
def solution(arr, K):
answer = 10001
list_a = list(itertools.combinations(arr, K))
for nums in list_a:
list_nums = list(set(nums))
max_n, min_n = max(list_nums), min(list_nums)
rtn = max_n - min_n
if rtn < answer:
answer = rtn
return answer
arr = [9, 11, 9, 6, 4, 19]
K = 4
ret = solution(arr, K)
print("solution 함수의 반환 값은", ret, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형
'Algorithm > COS' 카테고리의 다른 글
[COS Pro 1급, Python] 6차 5번 : 코인을 많이 획득하세요 (0) | 2022.03.01 |
---|---|
[COS Pro 1급, Python] 6차 4번 : 카드 섞기 (0) | 2022.03.01 |
[COS Pro 1급, Python] 6차 2번 : 단어를 순서대로 적으세요 (0) | 2022.02.28 |
[COS Pro 1급, Python] 6차 1번 : 꽃피는 봄이 언제 오나요 (0) | 2022.02.28 |
[COS Pro 1급, Python] 5차 10번 : 계산기만들기 (0) | 2022.02.28 |
Comments