1 | class Solution { |
以上参考 JDK 中 String#indexOf 实现,相比暴力解法效率更优,主要利用了首个字符匹配。
Reference
28. Find the Index of the First Occurrence in a String
Why does String.indexOf() not use KMP? - Stack Overflow
efficiency - Why does Java’s String class not implement a more efficient indexOf()? - Software Engineering Stack Exchange