之前在学KMP算法时一直理解不了获取next数组的函数是如何实现的,现在大概知道怎么一回事了,记录一下我对获取next数组的理解. KMP算法实现的原理就不再赘述了,先上KMP代码: 1 void getNext(char *pat, int *next) { 2 next[0] = -1; 3 int m = strlen(pat); 4 for (int i = 1; i < m; i++) { 5 int j = next[i - 1]; 6 while (j != -1 &&…
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "…