KMP algorithm always get run time error.


  • 0
    F

    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[100], 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?


  • 0
    S

    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.


  • 0
    F

    sorry, it is my mistake. you are right, it is due to index out of array range. Thanks.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.