From 6d523ad7c1600c594b1bb12af91766fcb660a722 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 25 Oct 2023 19:19:00 -0400 Subject: [PATCH] h-index cleanups --- leetcode/stuff.py | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/leetcode/stuff.py b/leetcode/stuff.py index d786145..580b18e 100644 --- a/leetcode/stuff.py +++ b/leetcode/stuff.py @@ -383,35 +383,11 @@ def collect_min_jumps_from_board(board: list[int]) -> list[int]: return jumps + [len(board) - 1] -def collect_scored_citations(citations: list[int]) -> list[int]: - return [ - i for i, v in enumerate(list(sorted(citations, reverse=True))) if v >= (i + 1) - ] - - -def collect_h_index_qualified_citations(citations: list[int]) -> set[int]: - census: dict[int, int] = collect_h_index_census_from_citations(citations) - return {k for k, v in census.items() if v >= k} - - -def collect_h_index_census_from_citations(citations: list[int]) -> dict[int, int]: - census: dict[int, int] = {} - - for n in set(citations): - census.setdefault(n, 0) - - for paper in citations: - if paper >= n: - census[n] += 1 - - return census - - def h_index(citations: list[int]) -> int: last_qualified = None - for i, citation in enumerate(list(sorted(citations, reverse=True))): - if citation >= i + 1: + for i, citation_count in enumerate(list(sorted(citations, reverse=True))): + if citation_count >= i + 1: last_qualified = i + 1 else: break