我的眼睛看世界

2010年06月18日

被问到一个题

Filed under: 感悟 — gcd0318 @ 07:12
也许是我孤陋寡闻吧,这个题应该是很常见的,没准江湖上早就流传了现成的答案:一个数组里,有一个数出现的次数大于50%,怎么找到它
其实思路特简单:每次从数组中去掉两个不一样的数,最后剩下的,如果全一样(包括只剩一个数),那就是这个数了
但是我多嘴,又问了一句:不包括等于50%的情况吧
对方立刻接我的话茬:包括吧
我肠子都悔青了,扭捏半天,胡扯了一大堆不相干的错话,一点边都不沾
几分钟以后,我突然意识到:如果恰好是50%,那就在最后还剩两个数的时候停下,然后从原数组里去掉一个和这俩数都不一样的数,然后再做一次;如果数组里只有这俩数没有第三个数,那就……是答案了
其实我经常如此的,很多答案,都是在问题过去之后一瞬间想到的,于是立刻后悔:当时若是……
唉,笨蛋
于是,最好,慢一点
Advertisements

7条评论 »

  1. 嘿嘿,偶有更好的解法。

    条评论 由 — 2010年06月20日 @ 07:17

  2. Just so you know, it appears to be like much like the location has been changed yet all over again. It is now (as of November 2011) portion in the Facebook Like Box plugin.

    条评论 由 Brooks Burnett — 2012年08月22日 @ 10:33

  3. I really wish that more cancer research similar to this will probably be done. I lost someone close to me to cancer, and we seriously need more robust screening methods for all people around the earth to help prevent this dreadful disease.

    条评论 由 Jonie Virgel — 2012年08月22日 @ 10:39

  4. Surprisingly revealing many many thanks, I do think your readers may well want further blog posts such as this carry on the excellent work.

    条评论 由 Galina Jinenez — 2012年08月22日 @ 11:06

  5. Oops, the should say “The beginning of February. I signed up on the 3rd.”

    条评论 由 Krysten Stouch — 2012年08月22日 @ 11:59

  6. I’m not heading to unfollow you Maybe your followers will not know what to say again to you

    条评论 由 Leo Asta — 2012年08月22日 @ 12:58

  7. So I had been speaking to a client today and he said he hired a guy for social media and was going to do this fabulous thing on facebook where he would make them much like the webpage before revealing a tab, and that they have to like a page to obtain access to a video, etc.

    条评论 由 Inger Rebelo — 2012年08月22日 @ 14:36


RSS feed for comments on this post. TrackBack URI

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: