class Solution {
public:
int strStr(string haystack, string needle) {
if(haystack.size()==0&&needle.size()==0)
{
return 0;
}
if(haystack.size()==0)
{
return -1;
}
else
{
return haystack.find(needle);
}
}
};
LeetCode:28.实现strStr()
最新推荐文章于 2022-04-25 12:35:16 发布
本文介绍了一个使用C++实现的字符串查找算法。该算法通过在haystack字符串中查找needle字符串的位置来工作,如果找到则返回needle字符串的起始位置,否则返回-1。此实现利用了C++标准库中的find成员函数。
929

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



