274.h-index.go 353 B

12345678910111213141516171819
  1. func hIndex(citations []int) int {
  2. n := len(citations)
  3. index := make([]int, n+1)
  4. for _, c := range citations {
  5. if n <= c {
  6. index[n]++
  7. } else {
  8. index[c]++
  9. }
  10. }
  11. for i := n; 1 <= i; i-- {
  12. if i <= index[i] {
  13. return i
  14. }
  15. index[i-1] += index[i] // So smart! The citations of h is the accumulation of index[h]~index[n]
  16. }
  17. return 0
  18. }