标签:图片 leetcode == bre src inf png return 代码
C++代码,题目相对不是很难
1 class Solution { 2 public: 3 int strStr(string haystack, string needle) { 4 if(needle.empty()) return 0; 5 int m=haystack.size(),n=needle.size(); 6 int flag=-1; 7 for(int i=0;i<=m-n;i++){ 8 if(haystack[i]==needle[0]){ 9 flag=i; 10 for(int j=1;j<n;j++){ 11 if(haystack[i+j]!=needle[j]){ 12 flag=-1;break; 13 } 14 } 15 if(flag>-1) return flag; 16 } 17 } 18 return flag; 19 } 20 };
leetcode 28. Implement strStr() 实现strStr()
标签:图片 leetcode == bre src inf png return 代码
原文地址:https://www.cnblogs.com/joelwang/p/10434805.html