Given string s, find the shortest string t, such that, t^m=s

前端 未结 4 994
北海茫月
北海茫月 2020-12-19 04:52

Given string s, find the shortest string t, such that, t^m=s.

Examples:

s=\"aabbb\" => t=\"aabbb\"
s=\"abab\"  => t = \"ab\"

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 05:04

    a modification to Boyer-Moore could possibly handle this in O(n) where n is length of s

    http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm

提交回复
热议问题