leetcode

28. Find the Index of the First Occurrence in a String

Naive solution code

Time complexity: O(nm)

Space complexity: O(1)

Runtime 0 ms
Beats 100.00% of users with Java

Memory 41.54 MB
Beats 23.37% of users with Java

KMP solution code

Time complexity: O(n+m)

Space complexity: O(m)

Runtime 0 ms
Beats 100.00% of users with Java

Memory 41.18 MB
Beats 78.65% of users with Java