SEIT3211 – Design and Analysis of Algorithms 23SE02CE030
PRACTICAL-11
AIM: Find the index of First Occurrence in the String
CODE:
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int strStr(string haystack, string needle) {
int n = [Link]();
int m = [Link]();
if(m == 0) return 0; // empty needle case
if(m > n) return -1; // needle longer than haystack
for(int i = 0; i <= n - m; ++i){
auto itH = [Link]() + i;
auto itN = [Link]();
int j = 0;
while(j < m && *(itH + j) == *(itN + j)){
j++;
}
if(j == m) return i; // found full match
}
return -1;
}
};
OUTPUT:
SEIT3211 – Design and Analysis of Algorithms 23SE02CE030
Submission Link :
[Link]
string/submissions/1780409127