LeetCode 274. H-Index

Problem:

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 at least h citations each, and the other N − h papers have no more than h citations each.”

For example, given citations = [3, 0, 6, 1, 5], which means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, his h-index is 3.

Note: If there are several possible values for h, the maximum one is taken as the h-index.

Hint:

  1. An easy approach is to sort the array first.
  2. What are the possible values of h-index?
  3. A faster approach is to use extra space.

Solution:

public class Solution {
    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int h = citations.length;
        for (int i = 0; i < citations.length; i++) {
            if (citations[i] >= h) return h;
            h--;
        }
        return 0;
    }
}

18 thoughts on “LeetCode 274. H-Index”

  1. 除皺特點 純度高,效果好 見效迅速,無創無痛 安全精準,表情自然 唯一在臨床有20多年的注射材料,全球超過11000000人使用 適用範圍 魚尾紋、額頭紋、眉間紋、鼻紋和頸部皺紋都可以祛除; 最適合於早期的、不太明顯的皺紋 不須使用任何的鎮靜劑或局部麻醉劑,且Botox除皺治療後可立即繼續進行正常的活動。 Botox除皺可以利用午休時間約診即可,完全不影響工作的安排。BOTOX肉毒桿菌素是一種高度純化的蛋白質,經過注射之後,能夠使導致動態皺紋的肌肉得到放鬆,它能夠阻斷導致肌肉收縮的神經細胞,使面部線條變得平滑並防止新皺紋形成。全球銷量第一品牌 在中國唯一獲得SFDA、FDA批准用於醫療美容的肉毒桿菌素 唯一一個擁有40年安全記錄的肉毒桿菌素 在70個國家獲得批准使用 BOTOX肉毒杆菌素

  2. 有關雷射、雷射除刺青、斑、曬斑、老人斑、太田母斑、顴骨母斑、點痣、疤痕、Q-開關紅寶石雷射、Q-開關釹-雅各雷射、Q-開關亞歷山卓雷射、二氧化碳雷射、鉺雅各雷射等一些相關、似是而非或有爭議的事項的披露與討論。

  3. Terms & Disclaimer Marie Claire (HK) Edition 豁免條款 南華傳媒清楚明示不提供任何明示或默示的擔保,包含但不限於商業適售性、特定目的之適用性及未侵害他人權利。 南華傳媒不保証此網頁的資訊、產品及服務將符合您的要求,或該資訊、產品及服務及其使用及取得之結果不受干擾、及時提供、正確、安全可靠或免於出錯。南華傳媒亦不保証軟體及硬體中的任何錯誤都將得到更正。 南華傳媒不負責,亦不承擔任何一切因使用此網頁而引致之任何意外、錯誤、遺漏、疏忽、干擾、經傳送或接收的錯誤、因下載而感染電腦病毒、誹謗、合約毀壞、版權或知識產權侵犯及所造成的任何損失。 南華傳媒不承擔任何經由或透過此網頁購買或取得之任何資訊、產品及服務,或接收之訊息,或進行之交易所衍生之替代商品及服務之購買成本,及您的傳輸或資料遭到未獲授權的存取或變造,所帶來之直接、間接、附帶、特別、衍生性或懲罰性賠償。 免責聲明的中、英文本出現分歧,以英文文本為準。   DISCLAIMER

  4. The Frenchman departed Manchester United’s US tour on Wednesday to be by the side of his heavily pregnant girlfriend Melanie Da Cruz, who went into labour shortly after his return. ‘I am Swan Anthony Martial’: Manchester United star confirms arrival and name of baby boy after arriving in Paris just in time to witness birth following his exit from US tour

  5. I have been browsing online more than 2 hours today, yet Inever found any interesting article like yours.It’s pretty worth enough for me. In my opinion, if all website owners and bloggers madegood content as you did, the internet will bemuch more useful than ever before.|I could not resist commenting. Perfectly written!|I’ll right away seize your rss feed as I can’t to find your e-mail subscription link or e-newsletter service.Do you’ve any? Please allow me understand in order that Icould subscribe. Thanks.|It is appropriate time to make some plans for the futureand it is time to be happy. I have read this post and if I could I want to suggest you someinteresting things or tips. Perhaps you could write next articlesreferring to this article. I want to read morethings about it!|It’s appropriate time to make a few plans for the long run and it is time to be happy.I have learn this submit and if I may I desire to suggest you some fascinating things or tips.Perhaps you can write next articles regarding this article.I wish to learn more issues about it!|I have been browsing on-line greater than three hoursas of late, but I never found any fascinating article like yours.It’s beautiful worth enough for me. Personally, if all web owners and bloggers made good content as you probably did,the internet will probably be a lot more useful than ever before.|Ahaa, its good discussion on the topic ofthis piece of writing at this place at this weblog, I have read all that, so now me also commentinghere.|I am sure this article has touched all the internet viewers, its reallyreally nice paragraph on building up new website.|Wow, this article is good, my younger sister is analyzing such things, so I am going to let know her.|Saved as a favorite, I love your site!|Way cool! Some very valid points! I appreciate youpenning this article and the rest of the site is also very good.|Hi, I do believe this is a great website. I stumbledupon it 😉I will return once again since I saved as a favorite it.Money and freedom is the best way to change, may you be richand continue to help others.|Woah! I’m really enjoying the template/theme of this website.It’s simple, yet effective. A lot of times it’s hard to get that“perfect balance” between usability and appearance.I must say you’ve done a fantastic job with this. Also, the blog loads extremelyfast for me on Internet explorer. Exceptional Blog!|These are genuinely impressive ideas in concerning blogging.You have touched some good factors here. Any way keep up wrinting.|I love what you guys tend to be up too. Such clever work andexposure! Keep up the amazing works guys I’ve incorporated you guys toblogroll.|Howdy! Someone in my Facebook group shared this site with us so I came togive it a look. I’m definitely loving the information. I’mbook-marking and will be tweeting this to my followers!Superb blog and outstanding style and design.|I enjoy what you guys are usually up too. This kind of cleverwork and exposure! Keep up the superb works guys I’ve incorporated you guys to blogroll.|Hi there would you mind sharing which blog platform you’re using?I’m looking to start my own blog in the near future but I’m having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.The reason I ask is because your design and style seems different then most blogs and I’m looking for something unique.P.S Apologies for being off-topic but I had to ask!|Howdy would you mind letting me know which webhost you’re using?I’ve loaded your blog in 3 different web browsers and I must say this blog loads a lot quicker then most.Can you recommend a good hosting provider at a reasonable price?Many thanks, I appreciate it!|I love it when folks get together and share opinions.Great website, keep it up!|Thank you for the auspicious writeup. It in fact was a amusement account it.Look advanced to more added agreeable from you! By the way, how could we communicate?|Hi there just wanted to give you a quick heads up. The words in your contentseem to be running off the screen in Internet explorer.I’m not sure if this is a format issue or something to do with browsercompatibility but I figured I’d post to let you know. The style anddesign look great though! Hope you get the issue solvedsoon. Thanks|This is a topic that’s close to my heart…Thank you! Where are your contact details though?|It’s very easy to find out any matter on net as compared to textbooks,as I found this piece of writing at this web page.|Does your site have a contact page? I’m having a tough time locating it but, I’d like to shoot you an e-mail.I’ve got some ideas for your blog you might be interested in hearing.Either way, great website and I look forward to seeingit develop over time.|Hi! I’ve been reading your blog for a long time now and finally got the bravery to go ahead and give you a shout outfrom Porter Texas! Just wanted to mention keep up the good job!|Greetings from Los angeles! I’m bored at work so I decided to browseyour website on my iphone during lunch break. I really likethe knowledge you provide here and can’t wait to take a look when I get home.I’m amazed at how fast your blog loaded on my cell phone ..I’m not even using WIFI, just 3G .. Anyhow, wonderful site!|Its like you read my thoughts! You appear to know so muchabout this, like you wrote the guide in it or something.I believe that you simply could do with a few to drive the message home a littlebit, however other than that, this is excellent blog.An excellent read. I will definitely be back.|I visited several websites however the audio feature for audio songs existing at this web page isactually wonderful.|Howdy, i read your blog from time to time and i own a similar one andi was just curious if you get a lot of spam comments?If so how do you protect against it, any plugin or anythingyou can recommend? I get so much lately it’s driving me crazy so any help is very much appreciated.|Greetings! Very helpful advice in this particular post!It’s the little changes that make the largest changes.Thanks a lot for sharing!|I seriously love your website.. Excellent colors & theme.Did you build this amazing site yourself? Please reply back as I’m wanting to create my veryown site and want to find out where you gotthis from or exactly what the theme is named. Thanks!|Howdy! This blog post couldn’t be written much better!Reading through this post reminds me of my previous roommate!He continually kept talking about this. I will send this information to him.Fairly certain he’s going to have a good read.Thanks for sharing!|Whoa! This blog looks exactly like my old one! It’s on a completely different subject but it has pretty much the same layout and design. Great choice ofcolors!|There is definately a lot to find out about this topic. I love all the points you’ve made.|You have made some decent points there. I looked on the web to find out more about the issue and found most individuals will goalong with your views on this website.|Hello, I check your blog on a regular basis.Your story-telling style is awesome, keep doing what you’re doing!|I simply could not depart your web site before suggesting that I extremely enjoyed the standard information an individual supply in your visitors?Is going to be again steadily to check up on new posts|I needed to thank you for this wonderful read!! I definitely loved every little bit of it.I have got you saved as a favorite to check out new things you post…|Hi, just wanted to tell you, I loved this blog post.It was helpful. Keep on posting!|Hello, I enjoy reading through your article. I like to write a little comment to support you.|I every time spent my half an hour to read this web site’scontent daily along with a cup of coffee.|I always emailed this blog post page to all myassociates, since if like to read it after that my links will too.|My coder is trying to convince me to move to .net from PHP.I have always disliked the idea because of the expenses. But he’s tryiong none theless. I’ve been using WordPress on a number of websites for about a year and am worried about switching to another platform.I have heard fantastic things about blogengine.net.Is there a way I can transfer all my wordpress posts into it?Any kind of help would be really appreciated!|Hi there! I could have sworn I’ve been to your blog before but after going through a few of the posts I realized it’s new to me.Anyhow, I’m certainly happy I found it and I’ll be bookmarkingit and checking back regularly!|Great article! That is the kind of info that should be shared across the internet.Disgrace on Google for no longer positioning thispost upper! Come on over and seek advice from my website .Thanks =)|Heya i am for the first time here. I found this board and I find It really useful & it helped me out a lot.I hope to give something back and help others like you aided me.|Hello there, There’s no doubt that your site might be having internetbrowser compatibility problems. When I take a look at your site in Safari, it looks fine however when opening in Internet Explorer, it’s got some overlapping issues.I simply wanted to provide you with a quick heads up!Other than that, great blog!|Someone essentially lend a hand to make critically posts I might state.That is the very first time I frequented your web page and up to now?I surprised with the research you made tocreate this actual post extraordinary. Wonderfultask!|Heya i’m for the first time here. I came across this board and I find It trulyhelpful & it helped me out a lot. I am hoping to give something back and help others like you helped me.|Hello! I simply want to give you a big thumbs up for theexcellent info you have here on this post. I will be returningto your site for more soon.|I always used to read article in news papers but now as I am auser of internet thus from now I am using net for articles, thanks to web.|Your mode of telling everything in this post is actually fastidious, all can easily be aware ofit, Thanks a lot.|Hi there, I found your web site by way of Google even as searching for a similar matter,your website came up, it seems to be great. I’ve bookmarked itin my google bookmarks.Hi there, simply was aware of your blog through Google, and found that it is really informative.I am going to be careful for brussels. I will be grateful if you happen to continue thisin future. Many folks will be benefited out of your writing.Cheers!|I’m curious to find out what blog platform you are workingwith? I’m experiencing some small security problems with my latest site and I would liketo find something more safeguarded. Do you have any suggestions?|I am really impressed with your writing skills and also withthe layout on your blog. Is this a paid theme or didyou modify it yourself? Anyway keep up the excellent quality writing, it is rare to see a nice blog like this one these days.|I’m extremely inspired with your writing abilities as neatlyas with the layout for your weblog. Is that this apaid subject matter or did you customize it yourself? Either way stay up the nice quality writing, it’s rare tolook a great blog like this one these days..|Hello, Neat post. There’s an issue with your web site in web explorer, may check this?IE still is the marketplace chief and a big component to people willleave out your excellent writing because of this problem.|I’m not sure where you’re getting your information, but great topic.I needs to spend some time learning much more or understanding more.Thanks for wonderful info I was looking for this info for my mission.|Hello, i think that i saw you visited my site thus i came to “return the favor”.Iam attempting to find things to improve my web site!I suppose its ok to use {some of|a few o\

  6. Jordan 12 Gym Red 2018 http://www.jordan12gymred.us.com/
    Nike Outlet satore http://www.nikefactoryoutletstoreonline.com/
    nike factory outlet http://www.nikefactoryoutletstoreonline.us/
    Nike Outlet http://www.nikestores.us.com/
    air jordan 33 http://www.jordan33.us/
    cheapjerseysfromchina http://www.cheapjerseysfromchina.us/
    custom nfl jerseys http://www.customnfljerseys.us/
    air jordan 11 concord http://www.jordan11concord.us.com/
    Jordan 12 Gym Red http://www.jordan12gymred.us/
    Jordan 12 Gym Red 2018 http://www.redjordan12.us/
    Yeezys http://www.yeezy.com.co/
    Yeezys http://www.yeezys.us.com/
    Yeezy Shoes http://www.yeezysupply.us.com/
    Yeezy Shoes http://www.yeezy-shoes.us.com/
    Yeezy Boost http://www.yeezy-boost350.com/
    Yeezy Boost 350 V2 http://www.yeezyboost350.us.com/
    Yeezy Boost 350 V2 Blue Tint http://www.yeezybluetint.com/
    Yeezy 500 Utility Black http://www.yeezy500utilityblack.com/
    Yeezy 500 Utility Black http://www.yeezy500utilityblack.us/
    Nike Air VaporMax http://www.vapor-max.org.uk/
    Salomon http://www.salomon-shoes.org.uk/
    Salomon http://www.salomons.me.uk/
    Salomon Shoes http://www.salomonspeedcross4.org.uk/
    Off White Jordan http://www.offwhitejordan1.com/
    Vapor Max http://www.nikevapormax.org.uk/
    Nike React Element 87 http://www.nikereactelement87.us.com/
    Nike Element 87 http://www.nikereactelement87.us/
    Nike Air Vapormax Plus http://www.nikeplus.us/
    Nike Outlet Store http://www.nike–outlet.us/
    Nike Outlet http://www.nikeoutletstoreonlineshopping.us/
    Nike Outlet http://www.nikeoutletonlineshopping.us/
    Nike NBA Jerseys http://www.nikenbajerseys.us/
    Air Max 97 http://www.nikeairmax.us/
    Air Max 2017 http://www.max2017.us/
    Air Jordan Shoes http://www.jordan-com.com/
    Jordan 11 Concord 2018 http://www.jordan11-concord.com/
    Cheap Yeezy Shoes http://www.cs7boots1.com/
    Wholesale Cheap NBA Jerseys http://www.cheapnba-jerseys.us/
    Birkenstock UK http://www.birkenstocksandalsuk.me.uk/
    NBA Jerseys http://www.basketball-jersey.us/
    Balenciaga UK http://www.balenciaga.me.uk/
    Balenciaga UK http://www.balenciagauk.org.uk/
    Balenciaga UK http://www.balenciagatriples.org.uk/
    Balenciaga http://www.birkenstocks.me.uk/
    Balenciaga Trainers http://www.balenciagatrainers.org.uk/
    Nike Air Max 270 http://www.airmax270.org.uk/
    Yeezy Shoes http://www.adidasyeezyshoes.org.uk/
    Yeezy Shoes http://www.adidasyeezyshoes.org.uk/

Leave a Reply