Golang solution using sort


  • 0
    C
    import "sort"
    func hIndex(citations []int) int {
        sort.Ints(citations)
    	l := len(citations)
    	for i := l - 1; i >= 0; i-- {
    		if citations[l-1-i] >= i+1 {
    			return i + 1
    		}
    	}
    	return 0
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.