由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - indexof有好的实现么
相关主题
find longest subarray with the equal number of 0's, 1's攒rp整理面试题(1)string match/text search
问个算法题还真从来没见过考KMP之类string matching算法的
问一道数据结构题查找substr的问题
= 和 == 用英语怎么说急问,Boggle (crossword)的解题思路?
Java的hashcode和equal函数有什么用?字串 查找的 最佳算法。
bloomberg onsite & offer其实我很想知道, 多少软工能25分钟内把heapsort写下
微软电面问几道较难的字符串题
突然想到一个关于string matching的题amazon 两轮电面
相关话题的讨论汇总
话题: targetstr话题: sourcestr话题: length话题: null话题: int
进入JobHunting版参与讨论
1 (共1页)
y***m
发帖数: 7027
1
土办法:
static int indexOf(string sourceStr, string targetStr)
{
if (sourceStr == null || targetStr == null)
throw new Exception("Null point excetion.");
if (targetStr.Length == 0) return 0;
if (targetStr.Length > sourceStr.Length) return -1;
char c = targetStr[0];
for (int i = 0; i < sourceStr.Length; i++)
{
if (sourceStr[i].Equals(c))
{
int Length = 1;
for (int j = 1; j < targetStr.Length && (i + j) < sourceStr.Length;
j++)
{
if (sourceStr[i + j].Equals(targetStr[j])) //break;
Length++;
}
if (Length == targetStr.Length)
return i;
}
}
return -1;
}
m*********e
发帖数: 55
2
KMP
经典算法

【在 y***m 的大作中提到】
: 土办法:
: static int indexOf(string sourceStr, string targetStr)
: {
: if (sourceStr == null || targetStr == null)
: throw new Exception("Null point excetion.");
: if (targetStr.Length == 0) return 0;
: if (targetStr.Length > sourceStr.Length) return -1;
: char c = targetStr[0];
: for (int i = 0; i < sourceStr.Length; i++)
: {

1 (共1页)
进入JobHunting版参与讨论
相关主题
amazon 两轮电面Java的hashcode和equal函数有什么用?
AMZ面经bloomberg onsite & offer
两道面试题,请大家说说看法微软电面
akamai面经突然想到一个关于string matching的题
find longest subarray with the equal number of 0's, 1's攒rp整理面试题(1)string match/text search
问个算法题还真从来没见过考KMP之类string matching算法的
问一道数据结构题查找substr的问题
= 和 == 用英语怎么说急问,Boggle (crossword)的解题思路?
相关话题的讨论汇总
话题: targetstr话题: sourcestr话题: length话题: null话题: int