Smallest and largest · Menor e maior
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.
Menor e maior
Encontre ambas as extremidades de uma lista em uma única passagem.
Mantenha dois valores de uma vez, ambos iniciando como o primeiro item. Verifique cada número contra ambos: ele pode substituir o menor, o maior ou nenhum dos dois.
Write min_max(nums) that returns a list [smallest, largest] using one · um loop and no min or · ou max. The list is never empty. · Escreva min_max(nums) que retorne uma lista [smallest, largest] usando um loop e sem min ou max. A lista nunca está vazia.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.