Most common substring of length X

前端 未结 8 2165
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 13:49

I have a string s and I want to search for the substring of length X that occurs most often in s. Overlapping substrings are allowed.

For example, if s=\"aoaoa\" and X=3

8条回答
  •  死守一世寂寞
    2021-02-09 14:25

    LZW algorithm does this

    This is exactly what Lempel-Ziv-Welch (LZW used in GIF image format) compression algorithm does. It finds prevalent repeated bytes and changes them for something short.

    LZW on Wikipedia

提交回复
热议问题