Substring algorithm

后端 未结 11 1335
小蘑菇
小蘑菇 2021-02-11 03:38

Can someone explain to me how to solve the substring problem iteratively?

The problem: given two strings S=S1S2S

11条回答
  •  悲&欢浪女
    2021-02-11 03:56

    It would go something like this:

    m==0? return true
    cs=0
    ct=0
    loop
        cs>n-m? break
        char at cs+ct in S==char at ct in T?
        yes:
            ct=ct+1
            ct==m? return true
        no:
            ct=0
            cs=cs+1
    
    end loop
    return false
    

提交回复
热议问题