leetcode第28题(返回字符串位置)

题目:返回字符串位置
eg. Input: haystack = “hello”, needle = “ll” Output: 2
Input: haystack = “aaaaa”, needle = “bba” Output: -1
思路:拆分成needle长度的字符,然后比较相同长度的字符串和needle
注意:字符串可以直接像数组一样操作

class Solution {
public int strStr(String haystack, String needle) {
        int len1=haystack.length();
        int len2=needle.length();
        if(len1

你可能感兴趣的:(leetcode第28题(返回字符串位置))