LeetCode 28. Implement strStr()

来源:互联网 发布:手机自动应答软件 编辑:程序博客网 时间:2024/05/01 21:30
public class Solution {    public int strStr(String haystack, String needle) {        int lh = haystack.length();int ln = needle.length();        if (lh < ln) return -1;        for (int i = 0; i <= lh - ln; i++) {        if (haystack.substring(i, i + ln).equals(needle)) return i;        }        return -1;    }}

0 0