Substring algorithm

后端 未结 11 1287
小蘑菇
小蘑菇 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 04:05

    if (T == string.Empty) return true;
    for (int i = 0; i <= S.Length - T.Length; i++) {
        for (int j = 0; j < T.Length; j++) {
            if (S[i + j] == T[j]) {
                if (j == (T.Length - 1)) return true;
            }
            else break;
        }
    }
    return false;
    

提交回复
热议问题