Next Array Introduction

Source: Internet
Author: User

first look at the solution for next array values such as:
Pattern string A B a a B c a C
Next value 0 1 1 2 2 3 1 2

The next array is solved by the next value of the first digit is 0, the next value of the second is 1, and the next value for each bit is then compared by the previous one. First compares the previous bit to its next value, and if it is equal, the next value of the bit is the next value of the previous bit plus 1; if not, go ahead and look for the next value to compare to the previous one. Until the next value corresponding to the contents of a bit is found to be equal to the previous one, then the value of this bit corresponds to the next value of 1, and if the first bit is found to be equal to the previous one, then the next value on the required bit is 1.
It seems very confusing to use the above example to do a specific operation again.
1. The first two bits must be 0 and 1.
2. When calculating the third position, look at the next value of the second B, 1, then the B and 1 corresponding to a to compare, different, the third position of the next value is 1, because it has been compared to the first, there is no comparison of the same phenomenon.
3. When calculating the fourth bit, look at the next value of the third position, 1, then A and 1 corresponding to a, the same, then the value of the next fourth bit A is the next value of a third bit plus 1. to 2. The value corresponding to the next value is the same as the value of the third bit, because it is implemented in the third position.
4. When calculating the fifth bit, look at the fourth bit of the next value, 2, then A and 2 corresponding to the B to compare, different, then the b corresponding to the next value 1 corresponding to a and fourth bit of a to compare, the same, then the next value of the fifth bit is the next value of second B plus 1, 2. The value corresponding to the next value is the same as the value of the fourth bit, because it is implemented in the second position.
5. When calculating the sixth position, look at the fifth bit of the next value of B, 2, then the B and 2 corresponding to the B to compare, the same, the sixth bit of the next value of C is the fifth bit B plus 1, 3, because it is in the fifth bit implementation of its next value corresponds to the same value as the fifth bit.
6. When calculating the seventh position, see the sixth bit of the next value of C, 3, then the C and 3 corresponding to a comparison, and then the 3rd bit of the next value of 1 corresponds to a and sixth bit C, still different, then the seventh bit next value is 1.

7. When calculating the eighth bit, looking at the seventh bit of the next value, 1, then A and 1 corresponding to a to compare, the same, the eighth bit of the next value of C is the seventh bit a next value plus 1, 2, because it is in the seventh bit and the implementation of its next value corresponds to the seventh bit.

Examples:

The next array of String ′ababaaababaa′ is () A, 012345678999
B, 0 12121111212
C, 011234223456
D, 0123012322345 Answer: C from reprint address: http://blog.csdn.net/quitepig/article/details/7933977

Next Array Introduction

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.