Efficient way to verify if a string is a rotated palindrome?

后端 未结 5 643
萌比男神i
萌比男神i 2021-01-12 03:49

A rotated palindrome is like \"1234321\", \"3432112\". The naive method will be cut the string into different pieces and concate them back and see if the string is a palindr

5条回答
  •  伪装坚强ぢ
    2021-01-12 04:45

    you can add the same pattern to the end of the original pattern. For example the pattern is 1234321, then you can add the same pattern to the end 12343211234321. After to do this, you can use the KMP or other substring match algotithms to find the string you want. if match, return ture.

提交回复
热议问题