From 56a878c5eb663f60b33d9e9c294d8c007df1c466 Mon Sep 17 00:00:00 2001 From: Sabyasachi <43935997+sabrajsab@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:45:31 +0530 Subject: [PATCH] leetcode #28 "implement strStr()" --- leetcode/cpp/string/28.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 leetcode/cpp/string/28.cpp 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); + } +};