Skip to content

Second largest · ⁨第二大的值⁩

English

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].

中文

第二大的值

返回第二大的不同值。与最大值相同的重复项不算,所以 [5, 5, 4] 得到 4,而不是 5。

一个简洁的思路:用 set(...) 去掉重复项,对结果排序,然后用 [-2] 取倒数第二个值。

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

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