Smallest and largest · הקטן והגדול ביותר
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. · כתוב פונקציה min_max(nums) שמחזירה רשימה [smallest, largest] באמצעות לולאה אחת וללא שימוש ב-min או ב-max. הרשימה לעולם אינה ריקה.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.