Partially match strings in case of List.contains(String)

后端 未结 9 865
夕颜
夕颜 2020-12-10 11:23

I have a List

List list = new ArrayList();
list.add(\"ABCD\");
list.add(\"EFGH\");
list.add(\"IJ KL\")         


        
9条回答
  •  借酒劲吻你
    2020-12-10 12:18

    If suggestion from Roadrunner-EX does not suffice then, I believe you are looking for Knuth–Morris–Pratt algorithm.

    Time complexity:

    • Time complexity of the table algorithm is O(n), preprocessing time
    • Time complexity of the search algorithm is O(k)

    So, the complexity of the overall algorithm is O(n + k).

    • n = Size of the List
    • k = length of pattern you are searching for

    Normal Brute-Force will have time complexity of O(nm)

    Moreover KMP algorithm will take same O(k) complexity for searching with same search string, on the other hand, it will be always O(km) for brute force approach.

提交回复
热议问题