Leetcode---28. 实现 strStr() Java实现

给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回  -1。

如:haystack = "aaaaa", needle = "bba" 返回2

public class Solution {
	public static void main(String[] args) {
		String s1 = "aaaabc";
		String s2 =  "abc";
		Solution s = new Solution();
		System.out.println(s.strStr(s1, s2));
	}
	public int strStr(String haystack, String needle) {
		if(haystack.length()==0 && needle.length()==0)return 0;
		int l=needle.length();
		for(int i=0;i

 

你可能感兴趣的:(LeetCode)