Created
May 17, 2020 14:37
-
-
Save SuryaPratapK/93905c88c3e23477e4c3451d0db90a82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> findAnagrams(string s, string p) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
vector<int> ans; | |
vector<int> hash(26,0); | |
vector<int> phash(26,0); | |
int window = p.size(); | |
int len = s.size(); | |
if(len<window) | |
return ans; | |
int left = 0,right = 0; | |
while(right<window) | |
{ | |
phash[p[right]-'a'] +=1; | |
hash[s[right++]-'a'] +=1; | |
} | |
right -=1; | |
while(right<len) | |
{ | |
if(phash == hash) | |
ans.push_back(left); | |
right+=1; | |
if(right!=len) | |
hash[s[right]-'a'] +=1; | |
hash[s[left]-'a'] -=1; | |
left+=1; | |
} | |
return ans; | |
} | |
}; |
These for streams in C++. Please read on it by searching. That will be best
:)
…On Sat, 19 Sep, 2020, 11:20 am Nikhil Sachan, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I always wonder what is the meaning of these lines ::-->>>
ios_base::sync_with_stdio(false);
cin.tie(NULL);
please explain
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/93905c88c3e23477e4c3451d0db90a82#gistcomment-3459637>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG73U3IRRZPUFS7DI3FE77LSGRBBNANCNFSM4RS2I3JA>
.
best advice.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I always wonder what is the meaning of these lines ::-->>>
ios_base::sync_with_stdio(false);
cin.tie(NULL);
please explain