Smallest and largest
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
This one builds on a lesson you haven't finished yet. Do that lesson first: · 이 과제는 아직 완료하지 않은 수업에 기반합니다. 먼저 해당 수업을 완료하세요:
Python Basics · Functions →
English
Smallest and largest
Find both ends of a list in a single pass.
Keep two values at once, both starting as the first item. Check each number against both: it may replace the smallest, the largest, or neither.
한국어
최솟값과 최댓값
리스트의 양끝을 한 번의 순회에서 찾으십시오.
처음 항목으로 시작하는 두 개의 값을 동시에 유지하십시오. 각 숫자를 두 값 모두와 비교하십시오: 최솟값을 교체하거나, 최댓값을 교체하거나, 혹은 아무것도 교체하지 않을 수도 있습니다.
Write min_max(nums) that returns a list [smallest, largest] using one loop and no min or max. The list is never empty.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.