1. 程式人生 > 其它 >【資料結構與演算法】經典面試題 ---- 字串匹配

【資料結構與演算法】經典面試題 ---- 字串匹配

技術標籤:# 資料結構與演算法練習演算法


文章目錄


在這裡插入圖片描述
方法一:利用String類的方法

public class Test01_字串匹配問題 {
    public static void main(String[] args) {
        String str1 = "矽矽谷 尚矽谷你尚矽 尚矽谷你尚矽谷你尚矽你好";
        String str2 = "尚矽谷你尚矽你";
        System.out.println(str1.indexOf(str2));
    }
}

在這裡插入圖片描述
方法二:暴力匹配

方法三:

KMP演算法

返回頂部