题目链接这里
public class Solution {
public int strStr(String haystack, String needle) {
out:for(int i=0;i<haystack.length()-needle.length()+1;i++)
{
for(int j=0;j<needle.length();j++)
{
if(haystack.charAt(i+j)!=needle.charAt(j))
{
continue out;
}
}
return i;
}
return -1;
}
}
本文介绍了一个简单的Java程序,用于实现在一个字符串中查找另一个字符串的功能。通过双重循环遍历的方式,对比目标字符串与源字符串中的子串是否相同,从而找到匹配的位置。
329

被折叠的 条评论
为什么被折叠?



