【資料結構與演算法】經典面試題 ---- 字串匹配
阿新 • • 發佈:2021-01-24
技術標籤:# 資料結構與演算法練習演算法
文章目錄
方法一:利用String類的方法
public class Test01_字串匹配問題 {
public static void main(String[] args) {
String str1 = "矽矽谷 尚矽谷你尚矽 尚矽谷你尚矽谷你尚矽你好";
String str2 = "尚矽谷你尚矽你";
System.out.println(str1.indexOf(str2));
}
}
方法二:暴力匹配
方法三: KMP演算法