Water King 2.0

Source: Internet
Author: User

Problem Description:

A three-person line designed a forum for irrigation. Information college students like to exchange irrigation above, legend in the forum there is a "water king", he not only likes to post, but also reply to other ID issued by each post. The "Water King" has been rumored to have posted more than half the number of posts. If you have a list of posts (including replies) for the current forum, and the ID of the author of the Post is in it, can you quickly find the legendary water king? (Refer to the core code) with the development of the Forum, the administrator found that the water king did not, but the statistical results show that there are three posts a lot of ID. According to the statistics of their posts more than 1/4, you can quickly find them from the list of posts?

Requires the design idea, code implementation, implementation, personal summary in the form of blog post.

Design ideas:

or in accordance with the first time to find the water king's ideas can be, but this time the return value is three, need to use the array to solve, the Ntimes 3 elements corresponding to the current traversal of the number of 3 IDs appear. If there is an ID in the traversal that differs from these 3 current IDs, we determine whether the current 3 ID has a ntimes of 0, and if so, the new traversal ID is replaced with 1 for its traversal number (that is, ntimes minus 1), if the current 3 ID ntimes is not 0, The ntimes of 3 IDs minus 1, which is the key to solving this problem. Because the non-water king ID is dissatisfied with the total number of posts of 1/4, and the same idea, the traversal ID and the current 3 ID is different, it is offset (that is, 3 of the current ID of the Ntimes value minus 1), the final remaining 3 current ID will always be 3 more than 1/4 water King ID.

Code implementation:

Realize:

Personal Summary:

Water King 2.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.