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. · اضغط تشغيل لرؤية المخرجات هنا.