KMP can pass in local, but always stuck at the test case "aaa", "aaa". And I found the problem is the dynamic allocation of the array "next" used in KMP algorithm. If I change to the definition like int next, then I can pass this test case, but obviously fail in another case, which has many many 'a's and one 'b' at the end.
My question is why dynamic allocation will cause run time error for the case "aaa", while static does not.
I do free the point before return?
Can you check if you get the same issue, with KMP?
Could you share your AC code and RE code in your post? Remember add some comment in it. I guess maybe your code run index out of array range in some time. But when it is static it is ok, when it dynamic it show up.