To find all the repeating substring in a given string

后端 未结 3 1316
感动是毒
感动是毒 2021-02-01 23:38

I recetly come across an interview question : To find all the repeating substring in a given string with a minimal size of 2. The algorithm should be efficient one.

Cod

3条回答
  •  青春惊慌失措
    2021-02-02 00:10

    I don't know how suffix tree can get all the repeating substring, string "mississippi" build suffix tree like this:

    sorry,I see. "At the end, iterate over each node with count>1 and print its path." "count" is how many this child node

    tree-->|---mississippi               m..mississippi
           |
           |---i-->|---ssi-->|---ssippi   i .. ississippi
           |       |         |
           |       |         |---ppi      issip,issipp,issippi
           |       |
           |       |---ppi                ip, ipp, ippi
           |
           |---s-->|---si-->|---ssippi    s .. ssissippi
           |       |        |
           |       |        |---ppi       ssip, ssipp, ssippi
           |       |
           |       |---i-->|---ssippi     si .. sissippi
           |               |
           |               |---ppi        sip, sipp, sippi
           |
           |---p-->|---pi                 p, pp, ppi
                   |
                   |---i                  p, pi
    
    --- Suffix Tree for "mississippi" ---
    

提交回复
热议问题