Tensorum
YouTubeகற்கத் தொடங்குங்கள்
LeetCode 274 · Counting Sort

H-Index

LeetCode 274 · நடுத்தரம் · தீர்வு, intuition & படிப்படியான வாக்த்ரூ

Sorted descending, h = first i where citations[i] ≤ i.

நடுத்தரம்ArraySortingCounting Sort
LeetCode இல் திற ↗

நான் H-Index (LeetCode 274) ஐ இப்படித் தீர்த்தேன் — Counting Sort பேட்டர்னின் ஒரு நடுத்தரம் பிராப்ளம். கீழே: intuition, படிப்படியான approach, என் accepted Python கோட், animated test cases மற்றும் line-by-line debugger.

கீழேயுள்ள விளக்கம் ஆங்கிலத்தில் உள்ளது.

Intuition

Sort citations from most to least. Walking down the list, paper i (0-based) still supports an h of i+1 as long as it has more than i citations; the first paper that doesn't stops the count.

Approach

  1. 1

    Sort descending.

  2. 2

    Advance i while citations[i] > i.

  3. 3

    Return i.

நான் எப்படித் தீர்த்தேன்

Sort descendingPythonO(n log n) time
class Solution:
    def hIndex(self, citations: List[int]) -> int:
        citations.sort(reverse=True)
        i=0
        while i<len(citations):
            if not citations[i]>i: 
                #6,5,3,1,0 -->citations
                #0,1,2,3,0 -->index
                break
            i+=1
        return i
ஸ்டெப்-த்ரூ ஏற்றுகிறது…

H-Index — அடிக்கடி கேட்கப்படும் கேள்விகள்

H-Index பின்னாலுள்ள intuition என்ன?

Sort citations from most to least. Walking down the list, paper i (0-based) still supports an h of i+1 as long as it has more than i citations; the first paper that doesn't stops the count.

H-Index (LeetCode 274) ஐ எப்படித் தீர்ப்பது?

1. Sort descending. 2. Advance i while citations[i] > i. 3. Return i.

H-Index இன் time மற்றும் space complexity என்ன?

Time: O(n log n). Space: O(1). (Accepted approach: Sort descending.)

H-Index இல் பொதுவான தவறுகள் என்ன?

A counting-sort version gives O(n).