/**
 * @param {number[]} citations
 * @return {number}
 */
var hIndex = function(citations) {
   for(let h = citations.length ; h>0;h-- ){
        let count = 0 
        for(let i= 0 ; i <citations.length;i++){
            if(citations[i]-h >=0){
                count++;
            }
        }
        if(count >= h){
            return h
        }
   }
   return 0
};
    
    
 
 
 
With Sorting

var hIndex = function(citations) {
    citations = citations.sort((a,b)=>b-a);
    for(i=citations.length; i>0; i--)
        if(citations[i-1]>=i)
            return i
    return 0    
}
    
    
 
 
 
             
          
Top comments (0)