class Solution {
public:
int strStr(const char *source, const char *target) {
// check if source or target is nullptr
if (source == nullptr || target == nullptr) {
return -1;
}
string s(source), t(target);
if (t.size() == 0) {
return 0;
}
for (int i = 0; i < s.size() - t.size() + 1; i++) {
if (s[i] != t[0]) {
continue;
}
for (int j = 1; j < t.size(); j++) {
if (s[i + j] != t[j]) {
break;
}
if (j == t.size() - 1) {
return i;
}
}
}
return -1;
}
};