# @lc code=start classSolution: defhIndex(self, citations: List[int]) -> int: ifnot citations: return0 citations.sort(reverse=True) n = len(citations) h = 0 for i inrange(n): if citations[i] >= i+1: h = i+1 else: break return h # @lc code=end
对比:顺序排序,从后往前遍历
1 2 3 4 5 6 7 8 9 10 11 12 13
classSolution: defhIndex(self, citations: List[int]) -> int: ifnot citations: return0 citations.sort() n = len(citations) h = 0 for i inrange(n-1, -1, -1): if citations[i] >= n-i: h += 1 else: break return h