Rakesh Reddy Peddamallu Posted on Jan 26 Leetcode - 274. H-Index #leetcode LeetCode Diary (27 Part Series) 1 Leetcode - 796. Rotate String 2 Leetcode - 845. Longest Mountain in Array ... 23 more parts... 3 Leetcode - 725. Split Linked List in Parts 4 Leetcode - 645. Set Mismatch 5 Leetcode - 70. Climbing Stairs 6 Leetcode - 1. Two Sum 7 Leetcode - 133. Clone Graph 8 Leetcode - 1768. Merge Strings Alternately 9 Leetcode - 1071. Greatest Common Divisor of Strings 10 Leetcode - 1431. Kids With the Greatest Number of Candies 11 Leetcode - 605. Can Place Flowers 12 Leetcode - 345. Reverse Vowels of a String 13 Leetcode - 151. Reverse Words in a String 14 Leetcode - 238. Product of Array Except Self 15 Leetcode - 334. Increasing Triplet Subsequence 16 Leetcode - 443. String Compression 17 Leetcode - 283. Move Zeroes 18 Leetcode - 392. Is Subsequence 19 Leetcode - 26. Remove Duplicates from Sorted Array 20 Leetcode - 80. Remove Duplicates from Sorted Array II 21 Leetcode - 169. Majority Element 22 Leetcode - 189. Rotate Array 23 Leetcode - 121. Best Time to Buy and Sell Stock 24 Leetcode - 55. Jump Game 25 Leetcode - 45. Jump Game II 26 Leetcode - 274. H-Index 27 Leetcode - 380. Insert Delete GetRandom O(1) /** * @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 }; Enter fullscreen mode Exit fullscreen mode 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 } Enter fullscreen mode Exit fullscreen mode Top comments (0) Subscribe Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Code of Conduct • Report abuse Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)