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