Блог пользователя burt_macklin_

Автор burt_macklin_, история, 5 лет назад, По-английски
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

First for each pair of string $$$(S1, S2)$$$, we find out the indices $$$\ 0 \leq i \leq S1.size ()\ $$$ such that $$$\ S1[i:]\ $$$ can overlap with $$$ S2[\ : min (\ S1.size() - i,\ S2.size())] $$$

Now it is always better to have one of the strings start from start of original string so we can do three checks with each string being the in start of the original string.

Then we can check all the possible start points for other $$$\ 2\ $$$ strings. The only problem being checking if some start position $$$\ i,\ j\ $$$ is okay in constant time. For each pair of string if they overlap we can check (using what we calculated in starting) if that overlap is fine.

I know My submission is not the cleanest way but still, happy to explain anything which is unclear.

»
5 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

There's editorial available for this task.