- (int)indexForPos:(NSString*)S with:(NSString*)T and:(int)index
{
int position = 0;
int c = 1;
int i = position;
while (i<[S length] && c<=index) {
int j=0;
while (j<[T length] && [S characterAtIndex:i]==[T characterAtIndex:j]) {
i++;
j++;
}
if (j==[T length]) {
position = i-[T length];
c++;
}
i=i-j+1;
}
return position;
}
在大字符串寻找第index次出现子串的位置(BF算法OC写法)
最新推荐文章于 2021-05-20 08:57:08 发布