Algorithms—28.Implement strStr()

来源:互联网 发布:日本女孩做饭知乎 编辑:程序博客网 时间:2024/05/18 02:13

思路:没太理解题目的意思,直接暴力破解。

public class Solution {    public int strStr(String haystack, String needle) {        if (needle.length()==0) {return 0;}        for (int i = 0; i <haystack.length()-needle.length()+1; i++) {if (haystack.substring(i,i+needle.length()).equals(needle)) {return i;}}        return -1;    }}


耗时:324ms,中下游。


0 0