/// <summary>
/// Brute-Force算法
/// </summary>
/// <param name="s">父串</param>
/// <param name="t">子串</param>
/// <returns>子串在父串的索引</returns>
public static int BF(string s, string t)
{
int i = 0, j = 0 ;
for(;i < s.Length && j <t.Length;)
{
if(s[i] == t[j])
{
i++;
j++;
}
else
{
i = i - j + 1;
j = 0;
}
}
if(j == t.Length)
{
return i - t.Length;
}
else
{
return -1;
}
}
/// Brute-Force算法
/// </summary>
/// <param name="s">父串</param>
/// <param name="t">子串</param>
/// <returns>子串在父串的索引</returns>
public static int BF(string s, string t)
{
int i = 0, j = 0 ;
for(;i < s.Length && j <t.Length;)
{
if(s[i] == t[j])
{
i++;
j++;
}
else
{
i = i - j + 1;
j = 0;
}
}
if(j == t.Length)
{
return i - t.Length;
}
else
{
return -1;
}
}