Skip to content

Smallest and largest · ⁨最小值和最大值⁩

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.

中文

最小值和最大值

只遍历一遍,就找出列表的两端。

同时记住两个值,开始时都等于第一个元素。把每个数和这两个值都比较一下:它可能替换最小值、最大值,或者都不替换。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩