Skip to content

Commit

Permalink
Create 1455_Check_If_a_Word_Occurs_As_a_Prefix_of_Any_Word_in_a_Sente…
Browse files Browse the repository at this point in the history
…nce.cpp
  • Loading branch information
Nothing-avil authored Dec 2, 2024
1 parent e57ec03 commit 260d372
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ███████╗ █████╗ ███╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗ ██╗ ██╗
// ██╔════╝ ██╔══██╗ ████╗ ██║ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║ ██║
// ███████╗ ███████║ ██╔██╗ ██║ ██║ ██║ ███████║ ██████╔╝ ██████╔╝ ███████║
// ╚════██║ ██╔══██║ ██║╚██╗██║ ██║ ██║ ██╔══██║ ██╔═██╗ ██╔══██╗ ██╔══██║
// ███████║ ██║ ██║ ██║ ╚████║ ██████╔╝ ██║ ██║ ██║ ██╗ ██████╔╝ ██║ ██║
// ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
#pragma GCC optimize("Ofast", "inline", "ffast-math", "unroll-loops","no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native", "f16c")
auto init = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 'c';
}();
class Solution {
public:
int isPrefixOfWord(string sentence, string searchWord) {
stringstream ss(sentence);
string t;
int res= 0, j = searchWord.size();
while(ss >> t){
res++;
int i=0;
while(t[i] == searchWord[i] && i< j){
i++;
}
if(i==j){
return res;
}
}
return -1;
}
};

0 comments on commit 260d372

Please sign in to comment.