Second largest · 第二大
Second largest
Return the second-biggest distinct value. Duplicates of the maximum don't count, so [5, 5, 4] gives 4, not 5.
One clean route: drop duplicates with set(...), sort the result, and take the value one in from the end with [-2].
ค่ามากเป็นอันดับสอง
return ค่า 第二大 distinct. Duplicate ของ maximum ไม่ถูกนับ, ดังนั้น [5, 5, 4] ให้ 4, ไม่ใช่ 5
เส้นทางที่สะอาด: ลบ duplicate ด้วย set(...), sort ผลลัพธ์, และ lấyค่าหนึ่งจากท้ายด้วย [-2]
Write second_largest(xs) that returns the second-largest distinct value in xs. You may assume there are at least two distinct values. · เขียน second_largest(xs)为了กลับค่า distinct第二大值ใน xs คุณสามารถสมมติว่ามีค่า distinct อย่างน้อยสองค่า
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่