Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have a…
#include<iostream> using namespace std; //不推荐用goto,当然用它更快 //辗转相除法求两数的最大公约数 int gcd(long int a,long int b){ int x=a<b?a:b; //获得较小者,用来做循环的约束值 ;i<x;x++){ //循环 if(a>b){ int r=a%b;//取余数 ){//能否整除判断 return b;//可以便输出 }else{//否则进行下一轮的算法 a=b,b=r; } }…
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? Hint: Expected runtime complexity is in O(log n) and the input is sorted. 这题是之前那道H-Index 求H指数的拓展,输入数组是有序的,让我们在O(log n)的时间内完成计算,看到这个时间复…