題目描述:
對於乙個給定的 source 字串和乙個 target 字串,你應該在 source 字串中找出 target 字串出現的第乙個位置(從0開始)。如果不存在,則返回 -1。
說明:在面試中我是否需要實現kmp演算法?
不需要,當這種問題出現在面試中時,面試官很可能只是想要測試一下你的基礎應用能力。當然你需要先跟面試官確認清楚要怎麼實現這個題。
樣例:如果 source = "source" 和 target = "target",返回 -1。
如果 source = "abcdabcdefg" 和 target = "bcd",返回 1。
public class solution
int i, j;
for (i = 0; i < source.length() - target.length() + 1; i++)
}if (j == target.length())
}return -1;
}
}
LintCode 13 字串查詢
對於乙個給定的 source 字串和乙個 target 字串,你應該在 source 字串中找出 target 字串出現的第乙個位置 從0開始 如果不存在,則返回 1。如果 source source 和 target target 返回 1。如果 source abcdabcdefg 和 targ...
LintCode 13 字串查詢
對於乙個給定的 source 字串和乙個 target 字串,你應該在 source 字串中找出 target 字串出現的第乙個位置 從0開始 如果不存在,則返回 1。說明 在面試中我是否需要實現kmp演算法?樣例 如果 source source 和 target target 返回 1。如果 s...
lintcode 13 字串查詢
字串查詢 中文english 對於乙個給定的 source 字串和乙個 target 字串,你應該在 source 字串中找出 target 字串出現的第乙個位置 從0開始 如果不存在,則返回 1。樣例 樣例 1 輸入 source source target target 輸出 1 樣例解釋 如果...