diff --git a/leetcode/cpp/string/28.cpp b/leetcode/cpp/string/28.cpp new file mode 100644 index 00000000..ce31afe2 --- /dev/null +++ b/leetcode/cpp/string/28.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + int strStr(string haystack, string needle) { + if(needle=="") + return 0; + double needle_hash=0, hay_hash=0; + for(int i=0;ihaystack.size()) + return -1; + hay_hash-=(haystack[k]-'a'); + hay_hash/=3; + hay_hash+=((haystack[k+needle.size()]-'a')*pow(3,needle.size()-1)); + k++; + }while(1); + } +};